rancher incentive quota usage - pos product search

This commit is contained in:
2025-09-27 10:20:01 +03:30
parent b3d2da6036
commit 7cd5cd3f66
14 changed files with 121 additions and 46 deletions

View File

@@ -14,8 +14,9 @@ from apps.warehouse.services.services import (
create_pre_sale
)
from apps.herd.pos.api.v1.serializers import RancherSerializer
from apps.product.models import QuotaDistribution, Product
from apps.product.models import QuotaDistribution, Product, QuotaUsage
from apps.warehouse import models as warehouse_models
from apps.livestock.models import LiveStockType
from apps.core.models import SystemConfig
from django.db.transaction import atomic
from apps.warehouse.exceptions import (
@@ -165,6 +166,44 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
# create pre sale for distribution
create_pre_sale(transaction=transaction, sale_item=item)
# # purchase quota usage of rancher
# if 'livestock_statistic' in item_data.keys():
# for item in item_data['livestock_statistic']:
# # get livestock by en name
# livestock_type = LiveStockType.objects.get(en_name=item['name'])
# # get usage & calculate
# usage = QuotaUsage.objects.filter(
# incentive_plan=item['id'],
# rancher=rancher,
# livestock_type=livestock_type,
# distribution=distribution
# )
# 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 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()
transaction.transaction_price = total_price
transaction.save()