fix party addd
This commit is contained in:
@@ -1,45 +0,0 @@
|
|||||||
from django.db.models import Count
|
|
||||||
from core.apps.finance.models import Expence
|
|
||||||
from django.core.management import BaseCommand
|
|
||||||
|
|
||||||
def get_duplicate_expenses_all():
|
|
||||||
"""
|
|
||||||
Barcha counterparty boyicha bir xil summada yaratilgan expenselarni topadi
|
|
||||||
"""
|
|
||||||
expences = Expence.objects.filter(
|
|
||||||
is_deleted=False,
|
|
||||||
counterparty__isnull=False
|
|
||||||
).values('counterparty', 'price', 'currency').annotate(
|
|
||||||
count=Count('id')
|
|
||||||
).filter(count__gt=1).order_by('-count')
|
|
||||||
|
|
||||||
return expences
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
|
|
||||||
|
|
||||||
duplicate_data = get_duplicate_expenses_all()
|
|
||||||
|
|
||||||
result = []
|
|
||||||
for item in duplicate_data:
|
|
||||||
expenses = Expence.objects.filter(
|
|
||||||
is_deleted=False,
|
|
||||||
counterparty_id=item['counterparty'],
|
|
||||||
price=item['price'],
|
|
||||||
currency=item['currency']
|
|
||||||
)
|
|
||||||
|
|
||||||
counterparty = expenses.first().counterparty if expenses.exists() else None
|
|
||||||
|
|
||||||
result.append({
|
|
||||||
'counterparty': counterparty,
|
|
||||||
'amount': item['price'],
|
|
||||||
'currency': item['currency'],
|
|
||||||
'count': item['count'],
|
|
||||||
'expenses': expenses
|
|
||||||
})
|
|
||||||
|
|
||||||
print(result)
|
|
||||||
print(len(result))
|
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ from core.apps.products.models import Product, Unity
|
|||||||
from core.apps.projects.models import Project, ProjectFolder
|
from core.apps.projects.models import Project, ProjectFolder
|
||||||
from core.apps.wherehouse.models import WhereHouse
|
from core.apps.wherehouse.models import WhereHouse
|
||||||
|
|
||||||
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MjI1MDQ1MCwiZXhwIjoxNzYyMzM2ODUwLCJuYmYiOjE3NjIyNTA0NTAsImp0aSI6IkVCOFpPTVZ1ZVJpMDlTOFciLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.8K1SbHvgJDyNYHE6BYIXYesZl-AmFjU6GMeEuJwM_jA"
|
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MjMzNjg2MSwiZXhwIjoxNzYyNDIzMjYxLCJuYmYiOjE3NjIzMzY4NjEsImp0aSI6Ino1SVpXRmlTVUJpMDA2eDciLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.yVOvrb-QjdYvCx6GJOW4T5y_N9-Lq2ThYFPu8_J0K3w"
|
||||||
|
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ class Command(BaseCommand):
|
|||||||
paid_amount = 0
|
paid_amount = 0
|
||||||
calculated_amount = 0
|
calculated_amount = 0
|
||||||
must_pay_amount = 0
|
must_pay_amount = 0
|
||||||
|
debt_amount = 0
|
||||||
for i in data["warehouse_products"]:
|
for i in data["warehouse_products"]:
|
||||||
product = Product.objects.filter(
|
product = Product.objects.filter(
|
||||||
name__icontains=i["product"]["name"]["uz"]
|
name__icontains=i["product"]["name"]["uz"]
|
||||||
@@ -108,6 +109,7 @@ class Command(BaseCommand):
|
|||||||
paid_amount += i["paid_amount"]
|
paid_amount += i["paid_amount"]
|
||||||
calculated_amount += i["calculated_amount"]
|
calculated_amount += i["calculated_amount"]
|
||||||
must_pay_amount += i["must_pay_amount"]
|
must_pay_amount += i["must_pay_amount"]
|
||||||
|
debt_amount += i['debt_amount']
|
||||||
orders.append(order)
|
orders.append(order)
|
||||||
party.orders.set(orders)
|
party.orders.set(orders)
|
||||||
PartyAmount.objects.get_or_create(
|
PartyAmount.objects.get_or_create(
|
||||||
@@ -117,6 +119,8 @@ class Command(BaseCommand):
|
|||||||
"calculated_amount": calculated_amount,
|
"calculated_amount": calculated_amount,
|
||||||
"paid_amount": paid_amount,
|
"paid_amount": paid_amount,
|
||||||
"payment_amount": must_pay_amount,
|
"payment_amount": must_pay_amount,
|
||||||
|
"debt_amount": debt_amount,
|
||||||
|
"total_expense_amount": item['item'],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.stdout.write("Parties added")
|
self.stdout.write("Parties added")
|
||||||
@@ -71,6 +71,7 @@ class Party(BaseModel):
|
|||||||
self.process = 75
|
self.process = 75
|
||||||
elif self.status == 'PARTY_IS_MADE':
|
elif self.status == 'PARTY_IS_MADE':
|
||||||
self.process = 100
|
self.process = 100
|
||||||
|
if not self.payment_percentage:
|
||||||
if hasattr(self, 'party_amount') and self.party_amount.paid_amount > 0 and self.party_amount.payment_amount > 0:
|
if hasattr(self, 'party_amount') and self.party_amount.paid_amount > 0 and self.party_amount.payment_amount > 0:
|
||||||
self.payment_percentage = (self.party_amount.paid_amount / self.party_amount.payment_amount) * 100
|
self.payment_percentage = (self.party_amount.paid_amount / self.party_amount.payment_amount) * 100
|
||||||
self.party_amount.save()
|
self.party_amount.save()
|
||||||
@@ -91,6 +92,8 @@ class PartyAmount(BaseModel):
|
|||||||
calculated_amount = models.BigIntegerField(default=0)
|
calculated_amount = models.BigIntegerField(default=0)
|
||||||
paid_amount = models.BigIntegerField(default=0)
|
paid_amount = models.BigIntegerField(default=0)
|
||||||
payment_amount = models.BigIntegerField(default=0)
|
payment_amount = models.BigIntegerField(default=0)
|
||||||
|
debt_amount = models.BigIntegerField(default=0)
|
||||||
|
total_expense_amount = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.party} amount'
|
return f'{self.party} amount'
|
||||||
|
|||||||
Reference in New Issue
Block a user