add herd size limit & pos sale type to quota
This commit is contained in:
@@ -89,6 +89,8 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
instance.final_price = validated_data.get('final_price', instance.final_price)
|
||||
instance.is_closed = validated_data.get('is_closed', instance.is_closed)
|
||||
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()
|
||||
|
||||
# update assigned organization many to many
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user