Compare commits
10 Commits
4360177c97
...
4aeb39fb5b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aeb39fb5b | ||
|
|
aacab8840f | ||
|
|
a32ef4e872 | ||
|
|
ce4603be07 | ||
|
|
f9141f3be0 | ||
|
|
59c1c455b2 | ||
|
|
5fcde1ec97 | ||
|
|
d665abe5ec | ||
|
|
d6ba8e006f | ||
|
|
c8d7f2d0b8 |
@@ -8,6 +8,7 @@ CORS_ALLOWED_ORIGINS = [
|
||||
"https://www.ibapp.uz",
|
||||
'https://test.ibapp.uz',
|
||||
'http://192.168.1.104:8081',
|
||||
'https://ikkita.felixits.uz',
|
||||
]
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
@@ -15,4 +16,5 @@ CSRF_TRUSTED_ORIGINS = [
|
||||
'http://127.0.0.1:8001',
|
||||
'https://test-uyqur.felixits.uz',
|
||||
"https://test-api.ibapp.uz",
|
||||
'https://bitta.felixits.uz',
|
||||
]
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(days=1),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=30),
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(days=365),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=3000),
|
||||
"ROTATE_REFRESH_TOKENS": True,
|
||||
"BLACKLIST_AFTER_ROTATION": True,
|
||||
"UPDATE_LAST_LOGIN": True,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.2.4 on 2025-12-05 14:43
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counterparty', '0009_counterpartybalance_total_balance'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='counterpartybalance',
|
||||
name='total_balance',
|
||||
),
|
||||
]
|
||||
@@ -134,25 +134,9 @@ class CounterpartyBalance(BaseModel):
|
||||
|
||||
@property
|
||||
def total_balance(self):
|
||||
PartyAmount = apps.get_model('orders', 'PartyAmount')
|
||||
Income = apps.get_model('finance', 'Income')
|
||||
Expense = apps.get_model('finance', 'Expense')
|
||||
usd_course = Decimal(UsdCourse.objects.first().value) if UsdCourse.objects.exists() else Decimal(12000)
|
||||
return self.total_balance_uzs + (self.total_balance_usd * usd_course)
|
||||
|
||||
total = Decimal(0)
|
||||
|
||||
for item in PartyAmount.objects.filter(party__orders__counterparty=self.counterparty):
|
||||
rate = item.exchange_rate or Decimal(1)
|
||||
total += Decimal(item.calculated_amount) * rate
|
||||
|
||||
for inc in Income.objects.filter(counterparty=self.counterparty):
|
||||
rate = inc.exchange_rate or Decimal(1)
|
||||
total += Decimal(inc.price) * rate
|
||||
|
||||
for exp in Expense.objects.filter(counterparty=self.counterparty):
|
||||
rate = exp.exchange_rate or Decimal(1)
|
||||
total -= Decimal(exp.price) * rate
|
||||
|
||||
return total
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.counterparty.name}"
|
||||
|
||||
@@ -59,6 +59,8 @@ class CounterpartyCreateSerializer(serializers.Serializer):
|
||||
return data
|
||||
|
||||
def create(self, validated_data):
|
||||
balance_data = validated_data.pop('balance', {}) or {}
|
||||
|
||||
with transaction.atomic():
|
||||
counterparty = Counterparty.objects.create(
|
||||
inn=validated_data.get('inn'),
|
||||
@@ -72,9 +74,13 @@ class CounterpartyCreateSerializer(serializers.Serializer):
|
||||
)
|
||||
CounterpartyBalance.objects.create(
|
||||
counterparty=counterparty,
|
||||
balance_uzs=validated_data.get('balance').get('balance_uzs'),
|
||||
balance_usd=validated_data.get('balance').get('balance_usd'),
|
||||
balance_date=validated_data.get('balance').get('balance_date'),
|
||||
balance_uzs=balance_data.get('balance_uzs', 0),
|
||||
balance_usd=balance_data.get('balance_usd', 0),
|
||||
balance_date=balance_data.get('balance_date'),
|
||||
kredit_usd=0,
|
||||
kredit_uzs=0,
|
||||
debit_usd=0,
|
||||
debit_uzs=0,
|
||||
)
|
||||
return counterparty
|
||||
|
||||
|
||||
@@ -239,7 +239,9 @@ class PartyStatisticsApiView(generics.GenericAPIView):
|
||||
queryset = self.filter_queryset(self.queryset)
|
||||
today = now().date()
|
||||
|
||||
usd_course = UsdCourse.objects.first().value if UsdCourse.objects.exists() else Decimal('12000')
|
||||
usd_course = Decimal(
|
||||
UsdCourse.objects.first().value if UsdCourse.objects.exists() else 12000
|
||||
)
|
||||
|
||||
usd = queryset.filter(currency='usd', is_deleted=False).aggregate(
|
||||
total_price_usd=Sum('party_amount__calculated_amount'),
|
||||
@@ -264,18 +266,24 @@ class PartyStatisticsApiView(generics.GenericAPIView):
|
||||
filter=Q(payment_date__lt=today)
|
||||
)
|
||||
)
|
||||
def safe(x): return x if x is not None else Decimal(0)
|
||||
|
||||
usd_total_in_uzs = safe(usd.get('total_price_usd')) * Decimal(usd_course)
|
||||
def safe(x):
|
||||
return Decimal(x) if x is not None else Decimal(0)
|
||||
|
||||
uzs_total = safe(uzs.get('total_price_uzs'))
|
||||
|
||||
total_balance = uzs_total + usd_total_in_uzs
|
||||
total = {
|
||||
"total_price": safe(uzs["total_price_uzs"]) + (safe(usd["total_price_usd"]) * usd_course),
|
||||
"cost_amount": safe(uzs["cost_amount_uzs"]) + (safe(usd["cost_amount_usd"]) * usd_course),
|
||||
"calculated_amount": safe(uzs["calculated_amount_uzs"]) + (safe(usd["calculated_amount_usd"]) * usd_course),
|
||||
"paid_amount": safe(uzs["paid_amount_uzs"]) + (safe(usd["paid_amount_usd"]) * usd_course),
|
||||
"payment_amount": safe(uzs["payment_amount_uzs"]) + (safe(usd["payment_amount_usd"]) * usd_course),
|
||||
"overdue_payments": safe(uzs["overdue_payments_uzs"]) + (safe(usd["overdue_payments_usd"]) * usd_course),
|
||||
}
|
||||
|
||||
res = {
|
||||
'usd': usd,
|
||||
'uzs': uzs,
|
||||
'total_balance': total_balance
|
||||
"usd": usd,
|
||||
"uzs": uzs,
|
||||
"total_balance": total
|
||||
}
|
||||
return Response(res, status=200)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user