added wherehouse json
This commit is contained in:
@@ -24,9 +24,8 @@ class Command(BaseCommand):
|
||||
product_name = item['product']['name']['uz']
|
||||
unit_name = item['unit']['name']['uz']
|
||||
warehouse_name = item['warehouse']['name']
|
||||
project_name = item['project']['name']
|
||||
project_name = item.get('project').get('name') if item.get('project') else None
|
||||
creator_name = item['creator']['full_name']
|
||||
|
||||
product = Product.objects.filter(name=product_name).first()
|
||||
unity = Unity.objects.filter(value=unit_name).first()
|
||||
wherehouse = WhereHouse.objects.filter(name=warehouse_name).first()
|
||||
@@ -35,7 +34,13 @@ class Command(BaseCommand):
|
||||
|
||||
delivery_date = datetime.strptime(item['delivery_date'], "%d.%m.%Y").date()
|
||||
created_at = datetime.strptime(item['created_at'], "%d.%m.%Y %H:%M")
|
||||
|
||||
if not product:
|
||||
product = Product.objects.create(
|
||||
name=product_name,
|
||||
product_code=item['product']['code'],
|
||||
type=item['product']['resource']['type'].upper(),
|
||||
unity=unity
|
||||
)
|
||||
Order.objects.update_or_create(
|
||||
status=item['status'].upper(),
|
||||
product=product,
|
||||
@@ -48,5 +53,6 @@ class Command(BaseCommand):
|
||||
created_at=created_at,
|
||||
date=delivery_date
|
||||
)
|
||||
break
|
||||
|
||||
self.stdout.write(self.style.SUCCESS("Orders imported successfully ✅"))
|
||||
|
||||
22
core/apps/wherehouse/management/commands/import_warehouse.py
Normal file
22
core/apps/wherehouse/management/commands/import_warehouse.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.wherehouse.models import WhereHouse
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('file_path', type=str, help='Path to JSON file')
|
||||
|
||||
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']['warehouses']:
|
||||
WhereHouse.objects.get_or_create(
|
||||
name=item['name']
|
||||
)
|
||||
|
||||
self.stdout.write("Warehouses added")
|
||||
Reference in New Issue
Block a user