pre sale & free sale deployment

This commit is contained in:
2025-09-21 16:54:55 +03:30
parent 7d58f46a77
commit 186d66bf84
6 changed files with 95 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
from apps.herd.services.services import rancher_quota_weight, get_rancher_statistics
from rest_framework.exceptions import APIException
from apps.warehouse.models import (
InventoryEntry,
InventoryQuotaSaleTransaction,
@@ -86,6 +87,7 @@ def create_extra_sale(
# set distribution warehouse balance to 0 because we have extra sale
sale_item.quota_distribution.warehouse_balance = 0
sale_item.quota_distribution.free_sale_balance += extra_weight
sale_item.quota_distribution.save()
# set transaction as free sale
@@ -112,10 +114,26 @@ def create_pre_sale(
"""
if sale_item.quota_distribution.pre_sale:
# create pre sale
pre_sale = QuotaPreSaleItem.objects.create(
transaction=transaction,
sale_item=sale_item,
distribution=sale_item.quota_distribution,
weight=sale_item.weight
)
try:
# create pre sale
pre_sale = QuotaPreSaleItem.objects.create(
transaction=transaction,
sale_item=sale_item,
distribution=sale_item.quota_distribution,
weight=sale_item.weight
)
# set transaction as pre sale
transaction.pre_sale_state = True
transaction.save()
# set sale item as pre sale
sale_item.is_pre_sale = True
sale_item.quota_distribution.pre_sale_balance += sale_item.weight
sale_item.save()
return pre_sale
except APIException as e:
pass
pass