mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Handle case when aggregation returns None
This commit is contained in:
parent
d25397e95c
commit
9153b62ea0
@ -788,7 +788,12 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
query = self.allocations.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
query = self.allocations.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||||
|
|
||||||
return query['q']
|
total = query['q']
|
||||||
|
|
||||||
|
if total is None:
|
||||||
|
total = Decimal(0)
|
||||||
|
|
||||||
|
return total
|
||||||
|
|
||||||
def sales_order_allocation_count(self):
|
def sales_order_allocation_count(self):
|
||||||
"""
|
"""
|
||||||
@ -797,14 +802,22 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
query = self.sales_order_allocations.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
query = self.sales_order_allocations.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||||
|
|
||||||
return query['q']
|
total = query['q']
|
||||||
|
|
||||||
|
if total is None:
|
||||||
|
total = Decimal(0)
|
||||||
|
|
||||||
|
return total
|
||||||
|
|
||||||
def allocation_count(self):
|
def allocation_count(self):
|
||||||
"""
|
"""
|
||||||
Return the total quantity allocated to builds or orders
|
Return the total quantity allocated to builds or orders
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.build_allocation_count() + self.sales_order_allocation_count()
|
bo = self.build_allocation_count()
|
||||||
|
so = self.sales_order_allocation_count()
|
||||||
|
|
||||||
|
return bo + so
|
||||||
|
|
||||||
def unallocated_quantity(self):
|
def unallocated_quantity(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user