add - IR to all sheba in devices
This commit is contained in:
@@ -27,7 +27,7 @@ def pos_organizations_sharing_information(
|
||||
"organization_name": item.organization.name,
|
||||
"bank_account": {
|
||||
"credit_card": item.organization.bank_information.first().card,
|
||||
"sheba": item.organization.bank_information.first().sheba,
|
||||
"sheba": "IR" + item.organization.bank_information.first().sheba,
|
||||
"account": item.organization.bank_information.first().account,
|
||||
} if item.organization.bank_information.exists() else {},
|
||||
"broker": item.broker.name if item.broker else None,
|
||||
@@ -57,7 +57,7 @@ def pos_organizations_sharing_information(
|
||||
"organization_name": item.organization.name,
|
||||
"bank_account": {
|
||||
"credit_card": item.organization.bank_information.first().card,
|
||||
"sheba": item.organization.bank_information.first().sheba,
|
||||
"sheba": "IR" + item.organization.bank_information.first().sheba,
|
||||
"account": item.organization.bank_information.first().account,
|
||||
} if item.organization.bank_information.exists() else {},
|
||||
"broker": item.broker.name if item.broker else None,
|
||||
@@ -118,7 +118,7 @@ def agency_organization_pos_info(
|
||||
"organization_name": agency.name,
|
||||
"bank_account": {
|
||||
"credit_card": agency.bank_information.first().card,
|
||||
"sheba": agency.bank_information.first().sheba,
|
||||
"sheba": "IR" + agency.bank_information.first().sheba,
|
||||
"account": agency.bank_information.first().account,
|
||||
} if agency.bank_information.exists() else {},
|
||||
"amount": agc_share_amount,
|
||||
|
||||
@@ -40,13 +40,13 @@ class POSFreeProductSerializer(serializers.ModelSerializer):
|
||||
}
|
||||
|
||||
representation['total_price'] = instance.price + instance.company_fee
|
||||
representation['main_shaba'] = instance.organization.bank_information.all().first().sheba # noqa
|
||||
representation['main_shaba'] = "IR" + instance.organization.bank_information.all().first().sheba # noqa
|
||||
|
||||
main_company = product_models.Organization.objects.get(
|
||||
national_unique_id='1111111111'
|
||||
)
|
||||
main_company_bank_account = main_company.bank_information.first()
|
||||
representation['company_sheba'] = main_company_bank_account.sheba
|
||||
representation['company_sheba'] = "IR" + main_company_bank_account.sheba
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
representation['pricing'] = { # noqa
|
||||
'main_account_sheba': organization.bank_information.first().sheba,
|
||||
'main_account_sheba': "IR" + organization.bank_information.first().sheba,
|
||||
'pricing_attributes': quota_attribute_value(instance.quota),
|
||||
'sharing': sharing_list,
|
||||
'base_prices': quota_pricing_items_by_type(instance.quota, sharing=sharing_list)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from django.db import transaction
|
||||
from django.db.models import Sum
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
from apps.product import models as product_models
|
||||
|
||||
@@ -15,14 +17,57 @@ class QuotaDistributionService:
|
||||
self.distribution = product_models.QuotaDistribution.objects.filter(
|
||||
quota=quota,
|
||||
assigned_organization=organization,
|
||||
quota__is_closed=False,
|
||||
warehouse_entry__gt=0
|
||||
).first()
|
||||
|
||||
@property
|
||||
def total_weight(self):
|
||||
def total_weight():
|
||||
return self.distribution.aggregate(
|
||||
total=Sum('weight')
|
||||
)['total'] or 0
|
||||
|
||||
pass
|
||||
@property
|
||||
def remaining_weight():
|
||||
return self.distribution.aggregate(
|
||||
total=Sum('remaining_weight')
|
||||
)['total'] or 0
|
||||
|
||||
def to_representation(self): # noqa
|
||||
return {
|
||||
'quota_id': self.quota.id,
|
||||
'quota_identity': self.quota.quota_id,
|
||||
'product': self.quota.product.name,
|
||||
'total_weight': self.total_weight,
|
||||
'remaining_weight': self.remaining_weight,
|
||||
'distribution_ids': self.distribution_ids,
|
||||
}
|
||||
|
||||
@transaction.atomic
|
||||
def consume(self, weight): # noqa
|
||||
"""
|
||||
Consume 'amount' of weight across all distributions in order.
|
||||
Automatically splits usage if needed.
|
||||
"""
|
||||
|
||||
if weight > self.remaining_weight:
|
||||
raise APIException('Not enough weight to consume')
|
||||
|
||||
remaining_to_consume = weight
|
||||
|
||||
for dist in self.distribution.select_for_update():
|
||||
if remaining_to_consume <= 0:
|
||||
break
|
||||
|
||||
available = dist.remaining_weight
|
||||
if available <= 0:
|
||||
continue
|
||||
|
||||
consume_amount = min(available, remaining_to_consume)
|
||||
dist.remaining_weight -= consume_amount
|
||||
dist.save(update_fields=["remaining_weight"])
|
||||
remaining_to_consume -= consume_amount
|
||||
|
||||
if remaining_to_consume > 0:
|
||||
raise APIException('Not enough weight to consume')
|
||||
|
||||
return True
|
||||
|
||||
@@ -74,7 +74,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(available_entries) # noqa
|
||||
if page is not None:
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True, context={'rancher': rancher.first(), 'device': device})
|
||||
# set custom message for paginator
|
||||
if not rancher:
|
||||
@@ -117,7 +117,7 @@ class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, DynamicSearchM
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(queryset)
|
||||
if page is not None:
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user