add new field to party
This commit is contained in:
@@ -7,4 +7,3 @@ class OrdersConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from . import admin
|
||||
from . import signals
|
||||
@@ -6,6 +6,7 @@ from core.apps.orders.models import Party, PartyAmount, Order, DeletedParty
|
||||
from core.apps.orders.serializers.order import MultipleOrderAddSerializer, OrderListSerializer
|
||||
from core.apps.accounts.models import User
|
||||
from core.apps.counterparty.serializers.counterparty import CounterpartyListPartySerializer
|
||||
from core.apps.shared.models import UsdCourse
|
||||
|
||||
|
||||
class PartyCreateSerializer(serializers.Serializer):
|
||||
@@ -20,6 +21,7 @@ class PartyCreateSerializer(serializers.Serializer):
|
||||
choices=[('CHECKED', 'tekshirildi'),('PROCESS', 'jarayonda')], required=False
|
||||
)
|
||||
audit_comment = serializers.CharField(required=False)
|
||||
currency = serializers.ChoiceField(choices=[('uzs', 'uzs'), ('usd', 'usd')])
|
||||
|
||||
def validate(self, data):
|
||||
user = User.objects.filter(id=data['mediator_id']).first()
|
||||
@@ -50,6 +52,11 @@ class PartyCreateSerializer(serializers.Serializer):
|
||||
total_price=resource.get('total_price'),
|
||||
qqs=resource.get('qqs'),
|
||||
))
|
||||
if validated_data.get('currency') == 'uzs':
|
||||
if resource.get('currency') == 'usd':
|
||||
usd_value = UsdCourse.objects.first().value
|
||||
total_price += resource.get('amount') * usd_value
|
||||
else:
|
||||
total_price += resource.get('amount')
|
||||
created_orders = Order.objects.bulk_create(orders)
|
||||
party = Party.objects.create(
|
||||
@@ -61,6 +68,7 @@ class PartyCreateSerializer(serializers.Serializer):
|
||||
audit_comment=validated_data.get('audit_comment'),
|
||||
discount=validated_data.get('discount'),
|
||||
discount_currency=validated_data.get('discount_currency'),
|
||||
currency=validated_data.get('currency'),
|
||||
)
|
||||
party.orders.add(*created_orders)
|
||||
party.save()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from .party import *
|
||||
@@ -1,36 +0,0 @@
|
||||
from django.db.models.signals import m2m_changed, post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from core.apps.orders.models.party import Party, PartyAmount
|
||||
|
||||
|
||||
# @receiver(m2m_changed, sender=Party)
|
||||
# def change_party_currency(sender, instance, action, **kwargs):
|
||||
# currencies = set(instance.orders.values_list("currency", flat=True))
|
||||
# print(instance.orders)
|
||||
# for order in instance.orders.all():
|
||||
# print(order.currency)
|
||||
# print(currencies)
|
||||
# if "usd" in currencies and "uzs" in currencies:
|
||||
# instance.currency = "uzs"
|
||||
# elif currencies == {"usd"}:
|
||||
# instance.currency = "usd"
|
||||
# elif currencies == {"uzs"}:
|
||||
# instance.currency = "uzs"
|
||||
# instance.save()
|
||||
|
||||
|
||||
# @receiver(post_save, sender=Party)
|
||||
# def change_party_currency(sender, instance, created, **kwargs):
|
||||
# currencies = set()
|
||||
# for order in instance.orders.all():
|
||||
# currencies.add(order.currency)
|
||||
# print(order.currency)
|
||||
# if "usd" in currencies and "uzs" in currencies:
|
||||
# instance.currency = "uzs"
|
||||
# elif currencies == {"usd"}:
|
||||
# instance.currency = "usd"
|
||||
# elif currencies == {"uzs"}:
|
||||
# instance.currency = "uzs"
|
||||
|
||||
# instance.save(update_fields=["currency"])
|
||||
Reference in New Issue
Block a user