fix - tarnsaction validation of pre sale & free sale / calculate weight in rancher statistic by rancher activity
This commit is contained in:
@@ -7,7 +7,7 @@ ENV_NAME=DEV
|
|||||||
# Database secrets
|
# Database secrets
|
||||||
DB_HOST=31.7.78.133
|
DB_HOST=31.7.78.133
|
||||||
DB_PORT=14352
|
DB_PORT=14352
|
||||||
DB_NAME=Development
|
DB_NAME=Production
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
from apps.livestock.models import LiveStock, TemporaryLiveStock
|
import typing
|
||||||
from decimal import Decimal
|
|
||||||
|
from django.db.models import Count, Q, Value
|
||||||
|
from django.db.models import Sum
|
||||||
|
from django.db.models.functions import Coalesce
|
||||||
|
|
||||||
from apps.herd.models import Rancher
|
from apps.herd.models import Rancher
|
||||||
|
from apps.herd.services.rancher_service import RancherService
|
||||||
|
from apps.livestock.models import LiveStock, TemporaryLiveStock
|
||||||
|
from apps.product.models import Quota, QuotaDistribution
|
||||||
from apps.warehouse.models import (
|
from apps.warehouse.models import (
|
||||||
InventoryEntry,
|
InventoryEntry,
|
||||||
InventoryQuotaSaleItem
|
InventoryQuotaSaleItem
|
||||||
)
|
)
|
||||||
from django.db.models import Sum
|
|
||||||
from apps.product.models import Quota, QuotaDistribution
|
LIVESTOCK_GROPES = {
|
||||||
from apps.herd.services.rancher_service import RancherService
|
'I': 'industrial', # صنعتی
|
||||||
from django.db.models import Count, Q, Value
|
'V': 'rural', # روستایی
|
||||||
from django.db.models.functions import Coalesce
|
'N': 'nomadic' # عشایری
|
||||||
import typing
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
def get_rancher_statistics(rancher: Rancher = None) -> typing.Any:
|
||||||
@@ -87,6 +94,7 @@ def rancher_quota_weight(
|
|||||||
# calculate quota base weight by livestock type & base total weight
|
# calculate quota base weight by livestock type & base total weight
|
||||||
for item in allocations: # noqa
|
for item in allocations: # noqa
|
||||||
if item.livestock_type:
|
if item.livestock_type:
|
||||||
|
if rancher.activity and LIVESTOCK_GROPES[rancher.activity] == item.livestock_group:
|
||||||
animal_type_fa = item.livestock_type.name
|
animal_type_fa = item.livestock_type.name
|
||||||
animal_type_en = item.livestock_type.en_name
|
animal_type_en = item.livestock_type.en_name
|
||||||
per_head = item.quantity_kg
|
per_head = item.quantity_kg
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
|||||||
if 'quota_distribution' in item.keys():
|
if 'quota_distribution' in item.keys():
|
||||||
distribution = QuotaDistribution.objects.get(id=item.get('quota_distribution'))
|
distribution = QuotaDistribution.objects.get(id=item.get('quota_distribution'))
|
||||||
|
|
||||||
|
if not distribution.pre_sale and not distribution.free_sale:
|
||||||
# if quota has not been in sale time
|
# if quota has not been in sale time
|
||||||
if not distribution.quota.is_in_sale_licence_time():
|
if not distribution.quota.is_in_sale_licence_time():
|
||||||
raise QuotaSaleTimeException()
|
raise QuotaSaleTimeException()
|
||||||
|
|||||||
Reference in New Issue
Block a user