add herd size limit & pos sale type to quota

This commit is contained in:
2025-09-27 14:39:29 +03:30
parent 826c49cdc1
commit dbb8bbd151
2 changed files with 37 additions and 27 deletions

View File

@@ -168,41 +168,49 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
# # purchase quota usage of rancher
# if 'livestock_statistic' in item_data.keys():
#
# # get list of livestock types object for transaction item
# livestock_types = {
# lt.en_name: lt
# for lt in LiveStockType.objects.filter(
# en_name__in=[i['name'] for i in item_data.get('livestock_statistic', [])]
# )
# }
#
# # get list of incentive plans object for transaction item
# incentive_plans = {
# iplan.id: iplan
# for iplan in []
# }
#
# for item in item_data['livestock_statistic']:
# # get livestock by en name
# livestock_type = LiveStockType.objects.get(en_name=item['name'])
# livestock_type = livestock_types.get(item['name'])
# if not livestock_types:
# continue
#
# is_incentive = item['id'] != 0
# # get usage & calculate
# usage = QuotaUsage.objects.filter(
# incentive_plan=item['id'],
#
# usage, created = QuotaUsage.objects.get_or_create(
# rancher=rancher,
# livestock_type=livestock_type,
# distribution=distribution
# distribution=distribution,
# incentive_plan=item['id'] if is_incentive else None,
# defaults={
# "count": item['count'],
# 'usage_type': 'incentive' if is_incentive else 'base',
# 'incentive_quota_used': item['total_weight'] if is_incentive else 0,
# 'base_quota_used': item['total_weight'] if is_incentive else 0
# }
# )
# if not usage.exists():
# usage = QuotaUsage(
# rancher=rancher,
# livestock_type=livestock_type,
# distribution=distribution,
# count=item['count'],
# )
# if item['id'] != 0: # if id != 0 it means using his incentive plan
# usage.incentive_plan = item['id'],
# usage.incentive_quota_used = item['total_weight'],
# usage.usage_type = 'incentive'
# usage.save()
# else:
# usage.incentive_plan = None
# usage.base_quota_used = item['total_weight'],
# usage.usage_type = 'base'
# usage.save()
# else:
# usage = usage.first()
#
# if not created:
# if usage.usage_type == 'incentive':
# usage.incentive_quota_used += item['total_weight']
# usage.save()
# elif usage.usage_type == 'base':
# usage.base_quota_used = item['total_weight']
# usage.save()
# else:
# usage.base_quota_used += item['total_weight']
# usage.save()
transaction.transaction_price = total_price
transaction.save()