fix - warehouse of quota stat in pos deviec complete - v2
This commit is contained in:
@@ -13,41 +13,42 @@ def warehouse_sold_and_balance(quota_stat: OrganizationQuotaStats):
|
||||
|
||||
quota_stat.sold_amount = total_sold
|
||||
quota_stat.inventory_entry_balance = quota_stat.inventory_received - total_sold
|
||||
# if quota_stat.inventory_entry_balance >= 0:
|
||||
|
||||
# calculate extra sales & mines total extra sales weight from new inventory entry
|
||||
# and set the warehouse balance
|
||||
if quota_stat.inventory_entry_balance >= 0:
|
||||
# calculate extra sales & mines total extra sales weight from new inventory entry
|
||||
# and set the warehouse balance
|
||||
|
||||
# extra_sales = quota_distribution.extra_sales.all()
|
||||
# total_extra_sales_weight = extra_sales.aggregate(total=Sum('weight'))['total'] or 0
|
||||
# if quota_distribution.free_sale_balance != 0:
|
||||
# if quota_distribution.warehouse_balance >= quota_distribution.free_sale_balance:
|
||||
# quota_distribution.warehouse_balance -= total_extra_sales_weight
|
||||
# quota_distribution.free_sale_balance = 0
|
||||
# else:
|
||||
# quota_distribution.free_sale_balance -= quota_distribution.warehouse_balance
|
||||
# quota_distribution.warehouse_balance = 0
|
||||
extra_sales = quota_stat.extra_sales.all()
|
||||
total_extra_sales_weight = extra_sales.aggregate(total=Sum('weight'))['total'] or 0
|
||||
if quota_stat.free_sale_balance != 0:
|
||||
if quota_stat.inventory_entry_balance >= quota_stat.free_sale_balance:
|
||||
quota_stat.inventory_entry_balance -= total_extra_sales_weight
|
||||
quota_stat.free_sale_balance = 0
|
||||
else:
|
||||
quota_stat.free_sale_balance -= quota_stat.inventory_entry_balance
|
||||
quota_stat.inventory_entry_balance = 0
|
||||
|
||||
# calculate pre_sales & mines total pre_sales weight from new inventory entry
|
||||
# and set the warehouse balance
|
||||
# calculate pre_sales & mines total pre_sales weight from new inventory entry
|
||||
# and set the warehouse balance
|
||||
|
||||
# pre_sales = quota_distribution.pre_sales.all()
|
||||
# total_pre_sales_weight = pre_sales.aggregate(total=Sum('weight'))['total'] or 0
|
||||
# if total_pre_sales_weight != 0:
|
||||
# if quota_distribution.warehouse_balance >= quota_distribution.pre_sale_balance:
|
||||
# quota_distribution.warehouse_balance -= total_pre_sales_weight
|
||||
# quota_distribution.pre_sale_balance = 0
|
||||
# else:
|
||||
# quota_distribution.pre_sale_balance -= quota_distribution.warehouse_balance
|
||||
# quota_distribution.warehouse_balance = 0
|
||||
pre_sales = quota_stat.pre_sales.all()
|
||||
total_pre_sales_weight = pre_sales.aggregate(total=Sum('weight'))['total'] or 0
|
||||
if total_pre_sales_weight != 0:
|
||||
if quota_stat.inventory_entry_balance >= quota_stat.pre_sale_balance:
|
||||
quota_stat.inventory_entry_balance -= total_pre_sales_weight
|
||||
quota_stat.pre_sale_balance = 0
|
||||
else:
|
||||
quota_stat.pre_sale_balance -= quota_stat.inventory_entry_balance
|
||||
quota_stat.inventory_entry_balance = 0
|
||||
|
||||
# 'free_sale_balance', 'pre_sale_balance'
|
||||
quota_stat.save(update_fields=['sold_amount', 'inventory_entry_balance'])
|
||||
quota_stat.save(update_fields=['sold_amount', 'inventory_entry_balance', 'free_sale_balance', 'pre_sale_balance'])
|
||||
|
||||
|
||||
@receiver(post_save, sender=InventoryQuotaSaleItem)
|
||||
@receiver(post_delete, sender=InventoryQuotaSaleItem)
|
||||
def update_distribution_warehouse_sold_and_balance(sender, instance: InventoryQuotaSaleItem, **kwargs):
|
||||
print(instance.quota_stat)
|
||||
print(instance.quota_stat.quota)
|
||||
# if object exists & pre sale is true
|
||||
if instance.quota_stat and not instance.quota_stat.quota.pre_sale:
|
||||
# if transaction status is success and warehouse management Done once, inventory_calculation set to true
|
||||
|
||||
Reference in New Issue
Block a user