You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
785 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from django.db.models import Sum
from goods_info.models import GoodsInventoryModel
def get_inventory_by_goods(goods_id, warehouse_id=0):
"""
1、可以返回指定货品的总库存
2、可以返回知道货品、指定仓库的库存
:param goods_id: 指定的货品ID
:param warehouse_id: 指定的仓库ID如果为0则查询所有仓库
:return:
"""
sum_inventory = 0
if warehouse_id == 0: # 查询总库存
result = GoodsInventoryModel.objects.filter(goods_id=goods_id).aggregate(sum=Sum('cur_inventory'))
else:
result = GoodsInventoryModel.objects.filter(goods_id=goods_id, warehouse_id=warehouse_id).aggregate(sum=Sum('cur_inventory'))
if result:
sum_inventory = result['sum']
return sum_inventory