some apis of pos
This commit is contained in:
25
apps/warehouse/services/services.py
Normal file
25
apps/warehouse/services/services.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from apps.warehouse.models import InventoryEntry, InventoryQuotaSaleTransaction
|
||||
from apps.herd.services.services import rancher_quota_weight
|
||||
from django.db.models import Sum
|
||||
|
||||
|
||||
def get_total_sold(inventory_entry, rancher):
|
||||
"""
|
||||
"""
|
||||
return (
|
||||
InventoryQuotaSaleTransaction.objects.filter(
|
||||
inventory_entry=inventory_entry,
|
||||
rancher=rancher
|
||||
).aggregate(total=Sum('weight'))['total'] or 0
|
||||
)
|
||||
|
||||
|
||||
def can_buy_from_inventory(rancher, inventory_entry: InventoryEntry):
|
||||
"""
|
||||
"""
|
||||
quota_weight = rancher_quota_weight(rancher, inventory_entry) # {total, by_type}
|
||||
total_allowed = quota_weight['total']
|
||||
|
||||
total_sold = get_total_sold(inventory_entry, rancher)
|
||||
|
||||
return total_sold < total_allowed
|
||||
Reference in New Issue
Block a user