add new management commands for finance and counterparty

This commit is contained in:
behruz-dev
2025-10-25 15:01:46 +05:00
parent 33d8f50ca2
commit 7ba54bfeb2
8 changed files with 12494 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
import json
from django.core.management import BaseCommand
from core.apps.counterparty.models import Counterparty
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("file_path", type=str)
def handle(self, *args, **options):
file_path = options['file_path']
with open(file_path, 'r') as f:
data = json.load(f)
for item in data['data']['data']:
Counterparty.objects.get_or_create(
name=item['name'],
defaults={
'phone': item['person']['phone'],
'inn': item['person']['tin'],
'balance_currency': item['balances'][0]['currency']['symbol'].lower() if item['balances'] else 'uzs',
'is_archived': item['is_archived'],
'balance': item['total_amount'],
'total_debit': item['debt_amount'],
'total_kredit': item['credit_amount'],
},
)
self.stdout.write("Counterparties added")

View File

@@ -0,0 +1,23 @@
import json
from django.core.management import BaseCommand
from core.apps.counterparty.models import CounterpartyFolder
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("file_path", type=str)
def handle(self, *args, **options):
file_path = options['file_path']
with open(file_path, 'r') as f:
data = json.load(f)
for item in data['data']:
CounterpartyFolder.objects.get_or_create(
name=item['name'],
)
self.stdout.write("Counterparty Folders added")

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.4 on 2025-10-25 14:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('counterparty', '0006_rename_debit_counterparty_debit_usd_and_more'),
]
operations = [
migrations.AlterField(
model_name='counterparty',
name='balance',
field=models.BigIntegerField(blank=True, null=True),
),
]

View File

@@ -41,7 +41,7 @@ class Counterparty(BaseModel):
district = models.ForeignKey( district = models.ForeignKey(
District, on_delete=models.SET_NULL, null=True, blank=True, related_name='counterparties' District, on_delete=models.SET_NULL, null=True, blank=True, related_name='counterparties'
) )
balance = models.PositiveBigIntegerField(null=True, blank=True) balance = models.BigIntegerField(null=True, blank=True)
balance_currency = models.CharField( balance_currency = models.CharField(
max_length=3, choices=[('usd', 'usd'), ('uzs', 'uzs')], null=True, blank=True max_length=3, choices=[('usd', 'usd'), ('uzs', 'uzs')], null=True, blank=True
) )

View File

@@ -0,0 +1,31 @@
import json
from django.core.management import BaseCommand
from core.apps.finance.models import CashTransaction
from core.apps.accounts.models import User
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('file_path', type=str)
def handle(self, *args, **options):
file_path = options['file_path']
with open(file_path, 'r') as f:
data = json.load(f)
for item in data['data']['cashs']:
users_data = item['users']
users_full_name = []
for user_data in users_data:
users_full_name.append(user_data['full_name'])
users = User.objects.filter(full_name__in=users_full_name)
cash_tx, created = CashTransaction.objects.get_or_create(
name=item['name']
)
cash_tx.employees.set(users)
cash_tx.save()
self.stdout.write("Cash Transactions added")

128
data/cash_transaction.json Normal file
View File

@@ -0,0 +1,128 @@
{
"data": {
"cashs": [
{
"id": 24,
"name": "FARM NAQT",
"status": "open",
"users": [
{
"id": 109,
"full_name": "Mirjonov Meronshox",
"image": null
},
{
"id": 104,
"full_name": "SuperAdminIskander",
"image": "https://backend.app.uyqur.uz/public/upload/image/neDbGZivNlWAz5nHopbl.webp"
},
{
"id": 138,
"full_name": "Baratova Zilola",
"image": null
},
{
"id": 306,
"full_name": "Uyqur Support",
"image": null
}
]
},
{
"id": 25,
"name": "FARM BUGHALTERIYA",
"status": "open",
"users": [
{
"id": 111,
"full_name": "MARDONOVA DILAFRUZ",
"image": null
},
{
"id": 104,
"full_name": "SuperAdminIskander",
"image": "https://backend.app.uyqur.uz/public/upload/image/neDbGZivNlWAz5nHopbl.webp"
},
{
"id": 138,
"full_name": "Baratova Zilola",
"image": null
},
{
"id": 306,
"full_name": "Uyqur Support",
"image": null
}
]
},
{
"id": 82,
"name": "Yunusobod BUHGALTERIYA",
"status": "open",
"users": [
{
"id": 104,
"full_name": "SuperAdminIskander",
"image": "https://backend.app.uyqur.uz/public/upload/image/neDbGZivNlWAz5nHopbl.webp"
},
{
"id": 111,
"full_name": "MARDONOVA DILAFRUZ",
"image": null
},
{
"id": 138,
"full_name": "Baratova Zilola",
"image": null
},
{
"id": 306,
"full_name": "Uyqur Support",
"image": null
}
]
},
{
"id": 83,
"name": "Yunusobod NAQT",
"status": "open",
"users": [
{
"id": 109,
"full_name": "Mirjonov Meronshox",
"image": null
},
{
"id": 138,
"full_name": "Baratova Zilola",
"image": null
},
{
"id": 104,
"full_name": "SuperAdminIskander",
"image": "https://backend.app.uyqur.uz/public/upload/image/neDbGZivNlWAz5nHopbl.webp"
},
{
"id": 306,
"full_name": "Uyqur Support",
"image": null
}
]
}
],
"cash_folders": [
{
"id": 3,
"name": "MARKETING",
"color": null,
"cashs_count": 0
}
]
},
"message": {
"uz": "Muvaffaqiyatli!",
"ru": "Успешно!",
"en": "Success!",
"tr": "Başarılı!"
}
}

12209
data/counterparty.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
{
"data": [
{
"id": 15,
"name": "marketing",
"color": null,
"company_persons_count": 103
},
{
"id": 16,
"name": "Qurilish bozorlik",
"color": null,
"company_persons_count": 0
},
{
"id": 23,
"name": "Административные расходы",
"color": null,
"company_persons_count": 15
},
{
"id": 32,
"name": "Mavrid административные расходы",
"color": null,
"company_persons_count": 1
},
{
"id": 34,
"name": "Buxgalter",
"color": null,
"company_persons_count": 1
},
{
"id": 36,
"name": "dur",
"color": null,
"company_persons_count": 0
},
{
"id": 44,
"name": "A",
"color": null,
"company_persons_count": 0
}
],
"message": {
"uz": "Muvaffaqiyatli!",
"ru": "Успешно!",
"en": "Success!",
"tr": "Başarılı!"
}
}