add: add kreditor and debitor
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-09-09 15:35
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('counterparty', '0004_counterparty_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='debit',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='kredit',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-09-09 16:52
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('counterparty', '0005_counterparty_debit_counterparty_kredit'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='counterparty',
|
||||||
|
old_name='debit',
|
||||||
|
new_name='debit_usd',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='counterparty',
|
||||||
|
old_name='kredit',
|
||||||
|
new_name='debit_uzs',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='kredit_usd',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='kredit_uzs',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='total_debit',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='counterparty',
|
||||||
|
name='total_kredit',
|
||||||
|
field=models.BigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -49,6 +49,13 @@ class Counterparty(BaseModel):
|
|||||||
comment = models.TextField(null=True, blank=True)
|
comment = models.TextField(null=True, blank=True)
|
||||||
is_archived = models.BooleanField(default=False)
|
is_archived = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
debit_usd = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
debit_uzs = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
total_debit = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
kredit_usd = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
kredit_uzs = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
total_kredit = models.BigIntegerField(default=0, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class CounterpartyListSerializer(serializers.ModelSerializer):
|
|||||||
fields = [
|
fields = [
|
||||||
'id', 'inn', 'name', 'phone', 'type', 'folder', 'type', 'region', 'district',
|
'id', 'inn', 'name', 'phone', 'type', 'folder', 'type', 'region', 'district',
|
||||||
'balance', 'balance_currency', 'balance_date', 'comment', 'is_archived',
|
'balance', 'balance_currency', 'balance_date', 'comment', 'is_archived',
|
||||||
|
'kredit_usd', 'kredit_uzs', 'total_kredit', 'debit_usd', 'debit_uzs', 'total_debit',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from core.apps.counterparty.filters.counterparty import CounterpartyFilter
|
|||||||
|
|
||||||
class CounterpartyListApiView(generics.ListAPIView):
|
class CounterpartyListApiView(generics.ListAPIView):
|
||||||
serializer_class = serializers.CounterpartyListSerializer
|
serializer_class = serializers.CounterpartyListSerializer
|
||||||
queryset = Counterparty.objects.exclude(is_archived=True).exclude(folder__isnull=True)
|
queryset = Counterparty.objects.exclude(is_archived=True).exclude(folder__isnull=False)
|
||||||
pagination_class = [HasRolePermission]
|
pagination_class = [HasRolePermission]
|
||||||
required_permissions = []
|
required_permissions = []
|
||||||
pagination_class = CustomPageNumberPagination
|
pagination_class = CustomPageNumberPagination
|
||||||
@@ -91,7 +91,7 @@ class FolderCounterpartyListApiView(generics.GenericAPIView):
|
|||||||
|
|
||||||
def get(self, reuqest, folder_id):
|
def get(self, reuqest, folder_id):
|
||||||
folder = get_object_or_404(CounterpartyFolder, id=folder_id)
|
folder = get_object_or_404(CounterpartyFolder, id=folder_id)
|
||||||
queryset = self.queryset.filter(fodler=folder).exclude(folder__isnull=False)
|
queryset = self.queryset.filter(fodler=folder).exclude(folder__isnull=True)
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
serializer = self.serializer_class(page, many=True)
|
serializer = self.serializer_class(page, many=True)
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-09-09 16:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('finance', '0015_alter_cashtransaction_expence_balance_usd_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='income',
|
||||||
|
name='exchange_rate',
|
||||||
|
field=models.PositiveBigIntegerField(blank=True, default=0, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -25,8 +25,8 @@ class Income(BaseModel):
|
|||||||
|
|
||||||
currency = models.CharField(choices=[('uzs', 'uzs'),('usd', 'usd')], max_length=3)
|
currency = models.CharField(choices=[('uzs', 'uzs'),('usd', 'usd')], max_length=3)
|
||||||
price = models.PositiveBigIntegerField()
|
price = models.PositiveBigIntegerField()
|
||||||
exchange_rate = models.PositiveBigIntegerField(default=0)
|
exchange_rate = models.PositiveBigIntegerField(default=0, null=True, blank=True)
|
||||||
date = models.DateField()
|
date = models.DateField(null=True, blank=True)
|
||||||
comment = models.TextField(null=True, blank=True)
|
comment = models.TextField(null=True, blank=True)
|
||||||
file = models.FileField(upload_to='finance/income/file/', null=True, blank=True)
|
file = models.FileField(upload_to='finance/income/file/', null=True, blank=True)
|
||||||
audit = models.CharField(max_length=200, null=True, blank=True)
|
audit = models.CharField(max_length=200, null=True, blank=True)
|
||||||
|
|||||||
@@ -38,14 +38,38 @@ class ExpenceCreateSerializer(serializers.ModelSerializer):
|
|||||||
cash_transaction.total_balance_uzs = cash_transaction.income_balance_uzs - cash_transaction.expence_balance_uzs
|
cash_transaction.total_balance_uzs = cash_transaction.income_balance_uzs - cash_transaction.expence_balance_uzs
|
||||||
if payment_type.total_uzs > expence.price:
|
if payment_type.total_uzs > expence.price:
|
||||||
payment_type.total_uzs -= expence.price
|
payment_type.total_uzs -= expence.price
|
||||||
|
|
||||||
|
if expence.counterparty:
|
||||||
|
if expence.counterparty.kredit_uzs != 0:
|
||||||
|
expence.counterparty.kredit_uzs -= expence.price
|
||||||
|
expence.counterparty.total_kredit -= expence.price
|
||||||
|
|
||||||
|
expence.counterparty.debit_uzs += expence.counterparty.kredit_uzs - expence.price
|
||||||
|
expence.counterparty.total_debit += expence.price
|
||||||
|
else:
|
||||||
|
expence.counterparty.debit_uzs += expence.price
|
||||||
|
expence.counterparty.total_debit += expence.price
|
||||||
|
|
||||||
elif validated_data.get('currency') == 'usd':
|
elif validated_data.get('currency') == 'usd':
|
||||||
cash_transaction.expence_balance_usd += expence.price
|
cash_transaction.expence_balance_usd += expence.price
|
||||||
cash_transaction.total_balance_usd = cash_transaction.income_balance_usd - cash_transaction.expence_balance_usd
|
cash_transaction.total_balance_usd = cash_transaction.income_balance_usd - cash_transaction.expence_balance_usd
|
||||||
if payment_type.total_usd > expence.price:
|
if payment_type.total_usd > expence.price:
|
||||||
payment_type.total_usd -= expence.price
|
payment_type.total_usd -= expence.price
|
||||||
|
|
||||||
|
if expence.counterparty:
|
||||||
|
if expence.counterparty.kredit_usd != 0:
|
||||||
|
expence.counterparty.kredit_usd -= validated_data.get('price')
|
||||||
|
expence.counterparty.total_kredit -= expence.price
|
||||||
|
|
||||||
|
expence.counterparty.debit_usd += expence.counterparty.kredit_usd - validated_data.get('price')
|
||||||
|
expence.counterparty.total_debit += expence.price
|
||||||
|
else:
|
||||||
|
expence.counterparty.debit_usd += validated_data.get('price')
|
||||||
|
expence.counterparty.total_debit += expence.price
|
||||||
|
|
||||||
cash_transaction.save()
|
cash_transaction.save()
|
||||||
payment_type.save()
|
payment_type.save()
|
||||||
|
expence.counterparty.save()
|
||||||
return expence
|
return expence
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -91,11 +91,34 @@ class IncomeCreateSerializer(serializers.ModelSerializer):
|
|||||||
cash_transaction.income_balance_uzs += income.price
|
cash_transaction.income_balance_uzs += income.price
|
||||||
cash_transaction.total_balance_uzs = cash_transaction.income_balance_uzs - cash_transaction.expence_balance_uzs
|
cash_transaction.total_balance_uzs = cash_transaction.income_balance_uzs - cash_transaction.expence_balance_uzs
|
||||||
payment_type.total_uzs += income.price
|
payment_type.total_uzs += income.price
|
||||||
|
|
||||||
|
if income.counterparty:
|
||||||
|
if income.counterparty.debit_uzs != 0:
|
||||||
|
income.counterparty.debit_uzs -= income.price
|
||||||
|
income.counterparty.total_debit -= income.price
|
||||||
|
|
||||||
|
income.counterparty.kredit_uzs += income.counterparty.debit_uzs - income.price
|
||||||
|
income.counterparty.total_kredit += income.price
|
||||||
|
else:
|
||||||
|
income.counterparty.kredit_uzs += income.price
|
||||||
|
income.counterparty.total_kredit += income.price
|
||||||
|
|
||||||
elif validated_data.get('currency') == 'usd':
|
elif validated_data.get('currency') == 'usd':
|
||||||
cash_transaction.income_balance_usd += income.price
|
cash_transaction.income_balance_usd += income.price
|
||||||
cash_transaction.total_balance_usd = cash_transaction.income_balance_usd - cash_transaction.expence_balance_usd
|
cash_transaction.total_balance_usd = cash_transaction.income_balance_usd - cash_transaction.expence_balance_usd
|
||||||
payment_type.total_usd += income.price
|
payment_type.total_usd += income.price
|
||||||
|
if income.counterparty:
|
||||||
|
if income.counterparty.debit_usd != 0:
|
||||||
|
income.counterparty.debit_usd -= validated_data.get('price')
|
||||||
|
income.counterparty.total_debit -= income.price
|
||||||
|
|
||||||
|
income.counterparty.kredit_usd += income.counterparty.debit_usd - validated_data.get('price')
|
||||||
|
income.counterparty.total_kredit += income.price
|
||||||
|
else:
|
||||||
|
income.counterparty.kredit_usd += validated_data.get('price')
|
||||||
|
income.counterparty.total_kredit += income.price
|
||||||
|
|
||||||
cash_transaction.save()
|
cash_transaction.save()
|
||||||
payment_type.save()
|
payment_type.save()
|
||||||
|
income.counterparty.save()
|
||||||
return income
|
return income
|
||||||
Reference in New Issue
Block a user