select_for_update to quota_id & add allowed cors origin new arg
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
from apps.authentication.models import OrganizationType, Organization
|
||||
from datetime import datetime
|
||||
|
||||
import jdatetime
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db import models
|
||||
from django.db import transaction
|
||||
from simple_history.models import HistoricalRecords
|
||||
|
||||
from apps.authentication.models import OrganizationType, Organization
|
||||
from apps.authorization.models import UserRelations
|
||||
from apps.livestock.models import LiveStockType
|
||||
from apps.core.models import BaseModel
|
||||
from apps.herd.models import Rancher
|
||||
from datetime import datetime
|
||||
from django.db import models
|
||||
import jdatetime
|
||||
from apps.livestock.models import LiveStockType
|
||||
|
||||
|
||||
class LivestockGroup(models.TextChoices):
|
||||
@@ -406,12 +409,16 @@ class Quota(BaseModel):
|
||||
def generate_quota_id(self): # noqa
|
||||
""" generate id for quota from 1001 """
|
||||
|
||||
last = Quota.objects.filter(quota_id__gte=1001, quota_id__lte=1999).order_by('-quota_id').first()
|
||||
if last:
|
||||
next_code = last.quota_id + 1
|
||||
else:
|
||||
next_code = 1001
|
||||
return next_code
|
||||
with transaction.atomic():
|
||||
last = Quota.objects.filter(
|
||||
quota_id__gte=10001,
|
||||
quota_id__lte=19999
|
||||
).select_for_update().order_by('-quota_id').first()
|
||||
if last:
|
||||
next_code = last.quota_id + 1
|
||||
else:
|
||||
next_code = 1001
|
||||
return next_code
|
||||
|
||||
def calculate_final_price(self):
|
||||
""" calculate final price of quota """
|
||||
|
||||
@@ -1,38 +1,30 @@
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.db.transaction import atomic
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.herd.models import Rancher
|
||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||
from apps.herd.services.services import get_rancher_statistics, rancher_quota_weight
|
||||
from apps.pos_device.models import POSFreeProducts
|
||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||
from apps.pos_device.services.services import pos_organizations_sharing_information
|
||||
from apps.product.exceptions import DistributionWeightException
|
||||
from apps.product.models import (
|
||||
QuotaDistribution,
|
||||
Product
|
||||
)
|
||||
from apps.product.services.services import (
|
||||
quota_live_stock_allocation_info,
|
||||
quota_incentive_plans_info,
|
||||
quota_brokers_value,
|
||||
quota_attribute_value
|
||||
)
|
||||
from apps.pos_device.services.services import pos_organizations_sharing_information
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from apps.warehouse.services.quota_usage_services import QuotaUsageService
|
||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||
from apps.product.exceptions import DistributionWeightException
|
||||
from apps.pos_device.models import POSFreeProducts
|
||||
from apps.warehouse.services.services import (
|
||||
create_extra_sale,
|
||||
create_pre_sale
|
||||
)
|
||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||
from apps.product.models import (
|
||||
QuotaDistribution,
|
||||
Product,
|
||||
QuotaUsage,
|
||||
IncentivePlan
|
||||
)
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from apps.livestock.models import LiveStockType
|
||||
from django.db.models.signals import post_save
|
||||
from apps.core.models import SystemConfig
|
||||
from django.db.transaction import atomic
|
||||
from apps.warehouse.exceptions import (
|
||||
TotalInventorySaleException
|
||||
)
|
||||
from rest_framework import serializers
|
||||
from apps.herd.models import Rancher
|
||||
from django.db.models import Q
|
||||
from django.db import models
|
||||
|
||||
|
||||
class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
@@ -66,6 +58,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
'sale_unit': instance.distribution.quota.sale_unit.unit,
|
||||
'id': instance.distribution.id
|
||||
}
|
||||
|
||||
representation['quota'] = {
|
||||
'quota_identity': instance.distribution.quota.quota_id,
|
||||
'quota_weight': instance.distribution.quota.quota_weight,
|
||||
@@ -74,6 +67,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
),
|
||||
'quota_incentive_plans': quota_incentive_plans_info(instance.distribution.quota)
|
||||
}
|
||||
|
||||
representation['product'] = {
|
||||
'image': instance.distribution.quota.product.img,
|
||||
'name': instance.distribution.quota.product.name,
|
||||
|
||||
Reference in New Issue
Block a user