fix - tarnsaction validation of pre sale & free sale / calculate weight in rancher statistic by rancher activity

This commit is contained in:
2025-11-11 09:50:19 +03:30
parent 3edcd9aa1c
commit f8bbda203f
3 changed files with 40 additions and 31 deletions

View File

@@ -252,15 +252,16 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
if 'quota_distribution' in item.keys():
distribution = QuotaDistribution.objects.get(id=item.get('quota_distribution'))
# if quota has not been in sale time
if not distribution.quota.is_in_sale_licence_time():
raise QuotaSaleTimeException()
total_sale_weight = distribution.sale_items.aggregate(
total=models.Sum('weight')
)['total'] or 0
if not distribution.pre_sale and not distribution.free_sale:
# if quota has not been in sale time
if not distribution.quota.is_in_sale_licence_time():
raise QuotaSaleTimeException()
total_sale_weight = distribution.sale_items.aggregate(
total=models.Sum('weight')
)['total'] or 0
if total_sale_weight + item.get('weight') > distribution.weight:
raise DistributionWeightException()
if total_sale_weight + item.get('weight') > distribution.weight:
raise DistributionWeightException()
return attrs