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

@@ -89,6 +89,8 @@ class QuotaSerializer(serializers.ModelSerializer):
instance.final_price = validated_data.get('final_price', instance.final_price) instance.final_price = validated_data.get('final_price', instance.final_price)
instance.is_closed = validated_data.get('is_closed', instance.is_closed) instance.is_closed = validated_data.get('is_closed', instance.is_closed)
instance.closed_at = validated_data.get('closed_at', instance.closed_at) instance.closed_at = validated_data.get('closed_at', instance.closed_at)
instance.limit_by_herd_size = validated_data.get('limit_by_herd_size', instance.limit_by_herd_size)
instance.pos_sale_type = validated_data.get('pos_sale_type', instance.pos_sale_type)
instance.save() instance.save()
# update assigned organization many to many # update assigned organization many to many

View File

@@ -168,41 +168,49 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
# # purchase quota usage of rancher # # purchase quota usage of rancher
# if 'livestock_statistic' in item_data.keys(): # 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']: # for item in item_data['livestock_statistic']:
# # get livestock by en name # # 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 # # get usage & calculate
# usage = QuotaUsage.objects.filter( #
# incentive_plan=item['id'], # usage, created = QuotaUsage.objects.get_or_create(
# rancher=rancher, # rancher=rancher,
# livestock_type=livestock_type, # 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( # if not created:
# 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 usage.usage_type == 'incentive': # if usage.usage_type == 'incentive':
# usage.incentive_quota_used += item['total_weight'] # usage.incentive_quota_used += item['total_weight']
# usage.save() # else:
# elif usage.usage_type == 'base': # usage.base_quota_used += item['total_weight']
# usage.base_quota_used = item['total_weight'] # usage.save()
# usage.save()
transaction.transaction_price = total_price transaction.transaction_price = total_price
transaction.save() transaction.save()