rancher quota usage in transaction - complete
This commit is contained in:
@@ -14,7 +14,12 @@ from apps.warehouse.services.services import (
|
|||||||
create_pre_sale
|
create_pre_sale
|
||||||
)
|
)
|
||||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||||
from apps.product.models import QuotaDistribution, Product, QuotaUsage
|
from apps.product.models import (
|
||||||
|
QuotaDistribution,
|
||||||
|
Product,
|
||||||
|
QuotaUsage,
|
||||||
|
IncentivePlan
|
||||||
|
)
|
||||||
from apps.warehouse import models as warehouse_models
|
from apps.warehouse import models as warehouse_models
|
||||||
from apps.livestock.models import LiveStockType
|
from apps.livestock.models import LiveStockType
|
||||||
from apps.core.models import SystemConfig
|
from apps.core.models import SystemConfig
|
||||||
@@ -166,51 +171,52 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
# create pre sale for distribution
|
# create pre sale for distribution
|
||||||
create_pre_sale(transaction=transaction, sale_item=item)
|
create_pre_sale(transaction=transaction, sale_item=item)
|
||||||
|
|
||||||
# # 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
|
# get list of livestock types object for transaction item
|
||||||
# livestock_types = {
|
livestock_types = {
|
||||||
# lt.en_name: lt
|
lt.en_name: lt
|
||||||
# for lt in LiveStockType.objects.filter(
|
for lt in LiveStockType.objects.filter(
|
||||||
# en_name__in=[i['name'] for i in item_data.get('livestock_statistic', [])]
|
en_name__in=[i['name'] for i in item_data.get('livestock_statistic', [])]
|
||||||
# )
|
)
|
||||||
# }
|
}
|
||||||
#
|
|
||||||
# # get list of incentive plans object for transaction item
|
# get list of incentive plans object for transaction item
|
||||||
# incentive_plans = {
|
incentive_plans = {
|
||||||
# iplan.id: iplan
|
iplan.id: iplan
|
||||||
# for iplan in []
|
for iplan in IncentivePlan.objects.all()
|
||||||
# }
|
}
|
||||||
#
|
|
||||||
# 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 = livestock_types.get(item['name'])
|
livestock_type = livestock_types.get(item['name'])
|
||||||
# if not livestock_types:
|
if not livestock_types:
|
||||||
# continue
|
continue
|
||||||
#
|
|
||||||
# is_incentive = item['id'] != 0
|
# true or false
|
||||||
# # get usage & calculate
|
is_incentive = item['id'] != 0
|
||||||
#
|
|
||||||
# usage, created = QuotaUsage.objects.get_or_create(
|
# get usage & calculate
|
||||||
# rancher=rancher,
|
usage, created = QuotaUsage.objects.get_or_create(
|
||||||
# livestock_type=livestock_type,
|
rancher=rancher,
|
||||||
# distribution=distribution,
|
livestock_type=livestock_type,
|
||||||
# incentive_plan=item['id'] if is_incentive else None,
|
distribution=distribution,
|
||||||
# defaults={
|
incentive_plan=incentive_plans.get(item['id']) if is_incentive else None,
|
||||||
# "count": item['count'],
|
defaults={
|
||||||
# 'usage_type': 'incentive' if is_incentive else 'base',
|
"count": item['count'],
|
||||||
# 'incentive_quota_used': item['total_weight'] if is_incentive else 0,
|
'usage_type': 'incentive' if is_incentive else 'base',
|
||||||
# 'base_quota_used': item['total_weight'] if is_incentive else 0
|
'incentive_quota_used': item['total_weight'] if is_incentive else 0,
|
||||||
# }
|
'base_quota_used': item['total_weight'] if is_incentive else 0
|
||||||
# )
|
}
|
||||||
#
|
)
|
||||||
# if not created:
|
|
||||||
# if usage.usage_type == 'incentive':
|
if not created:
|
||||||
# usage.incentive_quota_used += item['total_weight']
|
if usage.usage_type == 'incentive':
|
||||||
# else:
|
usage.incentive_quota_used += item['total_weight']
|
||||||
# usage.base_quota_used += item['total_weight']
|
else:
|
||||||
# usage.save()
|
usage.base_quota_used += item['total_weight']
|
||||||
|
usage.save()
|
||||||
|
|
||||||
transaction.transaction_price = total_price
|
transaction.transaction_price = total_price
|
||||||
transaction.save()
|
transaction.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user