fix - warehouse of quota stat in pos deviec complete - v2

This commit is contained in:
2025-11-26 17:39:46 +03:30
parent 64d5912a74
commit a4bfa46e5d
8 changed files with 38 additions and 33 deletions

View File

@@ -6,4 +6,4 @@ class AuthenticationConfig(AppConfig):
name = 'apps.authentication'
def ready(self):
import apps.authentication.signals
import apps.authentication.signals # noqa

View File

@@ -6,4 +6,4 @@ class AuthorizationConfig(AppConfig):
name = 'apps.authorization'
def ready(self):
import apps.authorization.signals
import apps.authorization.signals # noqa

View File

@@ -160,6 +160,7 @@ def rancher_quota_weight(
InventoryQuotaSaleItem,
quota_stat=quota_stat
)
print(rancher_remaining_usage)
if total_weight - rancher_remaining_usage < 0:
remaining_weight = 0

View File

@@ -6,4 +6,4 @@ class LivestockConfig(AppConfig):
name = 'apps.livestock'
def ready(self):
import apps.livestock.signals
import apps.livestock.signals # noqa

View File

@@ -6,4 +6,4 @@ class ProductConfig(AppConfig):
name = 'apps.product'
def ready(self):
import apps.product.signals
import apps.product.signals # noqa

View File

@@ -6,4 +6,5 @@ class WarehouseConfig(AppConfig):
name = 'apps.warehouse'
def ready(self):
pass
import apps.warehouse.signals # noqa
import apps.warehouse.signals.signals_v2 # noqa

View File

@@ -201,11 +201,13 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
gov_product = item_data.pop('gov_product', None)
free_product = item_data.pop('free_product', None)
distribution_id = item_data.pop('quota_distribution')
distribution = QuotaDistribution.objects.filter(
id=item_data.pop('quota_distribution')
id=distribution_id
).first() if 'quota_distribution' in item_data.keys() else None
quota_stat = OrganizationQuotaStats.objects.get(id=item_data.pop('quota_stat'))
quota_stat_id = item_data.pop('quota_stat')
quota_stat = OrganizationQuotaStats.objects.get(id=quota_stat_id)
# create item for transaction
item = warehouse_models.InventoryQuotaSaleItem.objects.create(
@@ -223,7 +225,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
total_price += item.total_price
# IF WE DO NOT HAVE DISTRIBUTION, THEN IT IS A FREE PRODUCT TRANSACTION
if 'quota_distribution' and 'quota_stat' in item_data.keys():
if distribution_id and quota_stat_id in item_data.keys():
# create extra sale for distribution
create_extra_sale(transaction=transaction, sale_item=item)

View File

@@ -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:
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
# 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