change party command
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.counterparty.models import Counterparty
|
||||
@@ -7,26 +8,29 @@ 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:
|
||||
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']:
|
||||
|
||||
for item in data["data"]["data"]:
|
||||
Counterparty.objects.get_or_create(
|
||||
name=item['name'],
|
||||
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'],
|
||||
"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")
|
||||
|
||||
Reference in New Issue
Block a user