add new management commands for finance and counterparty
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
]
|
||||
@@ -41,7 +41,7 @@ class Counterparty(BaseModel):
|
||||
district = models.ForeignKey(
|
||||
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(
|
||||
max_length=3, choices=[('usd', 'usd'), ('uzs', 'uzs')], null=True, blank=True
|
||||
)
|
||||
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user