counterparty: add counterpart
This commit is contained in:
12398
core/apps/counterparty/data/counterparty.json
Normal file
12398
core/apps/counterparty/data/counterparty.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,39 @@
|
||||
import json
|
||||
import json, requests
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.counterparty.models import CounterpartyFolder
|
||||
from core.apps.counterparty.models import CounterpartyFolder, Counterparty
|
||||
|
||||
headers = {
|
||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MTgzMzg2OSwiZXhwIjoxNzYxOTIwMjY5LCJuYmYiOjE3NjE4MzM4NjksImp0aSI6IjZSQWE1RzlyT0pGbXF1T2kiLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.ACT7oxl-A2eit_bzxeal2jF_xLa0klFObNBpp1HuheE"
|
||||
}
|
||||
|
||||
def get_counterparty(folder_id):
|
||||
url = f"https://backend.app.uyqur.uz/main/company-person-folder/view?company_person_folder_id={folder_id}&size=500"
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
return None
|
||||
|
||||
|
||||
def create_counterparty(data, folder):
|
||||
Counterparty.objects.get_or_create(
|
||||
name=data["name"],
|
||||
defaults={
|
||||
"phone": data["person"]["phone"],
|
||||
"inn": data["person"]["tin"],
|
||||
"balance_currency": (
|
||||
data["balances"][0]["currency"]["symbol"].lower()
|
||||
if data["balances"]
|
||||
else "uzs"
|
||||
),
|
||||
"is_archived": data["is_archived"],
|
||||
"balance": data["total_amount"],
|
||||
"total_debit": data["debt_amount"],
|
||||
"total_kredit": data["credit_amount"],
|
||||
"folder": folder
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -15,9 +47,12 @@ class Command(BaseCommand):
|
||||
data = json.load(f)
|
||||
|
||||
for item in data['data']:
|
||||
CounterpartyFolder.objects.get_or_create(
|
||||
folder, created = CounterpartyFolder.objects.get_or_create(
|
||||
name=item['name'],
|
||||
)
|
||||
data = get_counterparty(item['id'])
|
||||
for counterparty in data['data']['data']:
|
||||
create_counterparty(counterparty, folder)
|
||||
|
||||
self.stdout.write("Counterparty Folders added")
|
||||
|
||||
18
core/apps/orders/migrations/0031_order_type.py
Normal file
18
core/apps/orders/migrations/0031_order_type.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.4 on 2025-10-31 15:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('orders', '0030_alter_order_wherehouse_alter_party_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='type',
|
||||
field=models.CharField(choices=[('order', 'order'), ('party', 'party')], default='order', max_length=6),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,3 @@
|
||||
from .order import *
|
||||
from .order_offer import *
|
||||
from ..order_offer import *
|
||||
from .party import *
|
||||
@@ -16,7 +16,7 @@ class Order(BaseModel):
|
||||
('CANCELLED', "bekor qilindi"),
|
||||
('ACCEPTED', 'qabul qilindi'),
|
||||
)
|
||||
|
||||
type = models.CharField(max_length=6, choices=[('order', 'order'), ('party', 'party')], default='order')
|
||||
product = models.ForeignKey(
|
||||
Product, on_delete=models.CASCADE, related_name='orders'
|
||||
)
|
||||
|
||||
18
core/apps/products/migrations/0008_alter_unity_value.py
Normal file
18
core/apps/products/migrations/0008_alter_unity_value.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.4 on 2025-10-31 15:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('products', '0007_alter_product_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='unity',
|
||||
name='value',
|
||||
field=models.CharField(max_length=50, unique=True),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user