add purchace limitations system for rancher - add incentive plans to rancher entries data

This commit is contained in:
2025-08-26 12:18:10 +03:30
parent b5dfcebafe
commit c0b6b8ddca
12 changed files with 142 additions and 14 deletions

View File

@@ -1,5 +1,8 @@
from apps.herd.services.services import get_rancher_statistics, rancher_quota_weight
from apps.product.services.services import quota_live_stock_allocation_info
from apps.product.services.services import (
quota_live_stock_allocation_info,
quota_incentive_plans_info
)
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
from apps.herd.pos.api.v1.serializers import RancherSerializer
from apps.warehouse.exceptions import (
@@ -46,7 +49,8 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
'quota_weight': instance.distribution.quota.quota_weight,
'quota_livestock_allocations': quota_live_stock_allocation_info(
instance.distribution.quota
)
),
'quota_incentive_plans': quota_incentive_plans_info(instance.distribution.quota)
}
representation['product'] = {
'name': instance.distribution.quota.product.name,

View File

@@ -1,5 +1,6 @@
from apps.warehouse.models import InventoryEntry, InventoryQuotaSaleTransaction
from apps.herd.services.services import rancher_quota_weight, get_rancher_statistics
from apps.core.models import SystemConfig
from django.db.models import Sum
@@ -17,6 +18,12 @@ def get_total_sold(inventory_entry, rancher):
def can_buy_from_inventory(rancher, inventory_entry: InventoryEntry):
"""
"""
if SystemConfig.get("IGNORE_ALL_RANCHER_PURCHASE_LIMITS") == "true":
return True
if rancher.ignore_purchase_limit:
return True
quota_weight = rancher_quota_weight(rancher, inventory_entry) # {total, by_type}
total_allowed = quota_weight['total']