fix
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import json, requests
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from core.apps.wherehouse.models import WhereHouse, StockMovemend, StockMovmendProduct, Inventory
|
||||||
|
from core.apps.products.models import Product, Unity
|
||||||
|
from core.apps.accounts.models import User
|
||||||
|
from core.apps.projects.models import ProjectFolder
|
||||||
|
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MTkyMDM2MSwiZXhwIjoxNzYyMDA2NzYxLCJuYmYiOjE3NjE5MjAzNjEsImp0aSI6Inhqak81azJLc2pSaEJJOGUiLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.ZcREfvT21qpd9eK_-zBumKBtaKKJ-l9QoudSLZ3IpP4"
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_data():
|
||||||
|
url = f'https://backend.app.uyqur.uz/main/warehouse-transfer/view?size=524'
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def get_product(stock_movement_id):
|
||||||
|
url = f"https://backend.app.uyqur.uz/main/warehouse-transfer/view?id={stock_movement_id}"
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
data = get_data()
|
||||||
|
movemend_types = {
|
||||||
|
"pending": "EXPECTED",
|
||||||
|
"recieved": "ACCEPTED",
|
||||||
|
"rejected": "CANCELLED"
|
||||||
|
}
|
||||||
|
for item in data['data']['data']:
|
||||||
|
sender_warehouse = WhereHouse.objects.filter(name=item['sender_warehouse']['name']).first()
|
||||||
|
recieved_warehouse = WhereHouse.objects.filter(name=item['recieved_warehouse']['name']).first()
|
||||||
|
project_folder = None
|
||||||
|
if item.get('project'):
|
||||||
|
project_folder = ProjectFolder.objects.filter(name=item['project']['name']).first()
|
||||||
|
user = None
|
||||||
|
if item.get('recieved_user'):
|
||||||
|
user = User.objects.filter(full_name=item['recieved_user']['full_name']).first()
|
||||||
|
stock_movemend, created = StockMovemend.objects.get_or_create(
|
||||||
|
number=item['id'],
|
||||||
|
defaults={
|
||||||
|
"wherehouse_to": recieved_warehouse,
|
||||||
|
"wherehouse_from": sender_warehouse,
|
||||||
|
"recipient": user,
|
||||||
|
"project_folder": project_folder,
|
||||||
|
"movemend_type": movemend_types.get(item['status']),
|
||||||
|
"date": datetime.strptime(item['date'], "%d.%m.%Y"),
|
||||||
|
"comment": item['description'],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
data = get_product(item['id'])
|
||||||
|
if data.get('data'):
|
||||||
|
for product in data['data']['warehouse_products']:
|
||||||
|
product_obj = Product.objects.filter(name=product['product']['name']['uz']).first()
|
||||||
|
unit = Unity.objects.filter(value=product['unit']['name']['uz']).first()
|
||||||
|
wherehouse = WhereHouse.objects.filter(name=product['warehouse']['name']).first()
|
||||||
|
inventory = Inventory.objects.filter(
|
||||||
|
product=product_obj,
|
||||||
|
unity=unit,
|
||||||
|
wherehouse=wherehouse
|
||||||
|
).first()
|
||||||
|
StockMovmendProduct.objects.get_or_create(
|
||||||
|
inventory=inventory,
|
||||||
|
quantity=product['initial_quantity'],
|
||||||
|
stock_movemend=stock_movemend
|
||||||
|
)
|
||||||
|
self.stdout.write("Stock Movemend qo'shildi")
|
||||||
Reference in New Issue
Block a user