Merge pull request #29 from xoliqberdiyev/test
product: product folders import is done
This commit is contained in:
80
core/apps/products/data/product_folder.json
Normal file
80
core/apps/products/data/product_folder.json
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 43,
|
||||||
|
"name": {
|
||||||
|
"ru": "\u0422\u043e\u0432\u0430\u0440\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0423\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u0430\u043d\u0430",
|
||||||
|
"uz": "O'zbekiston mahsulotlar bazasi"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 44,
|
||||||
|
"name": {
|
||||||
|
"uz": "Marketing",
|
||||||
|
"ru": "Marketing"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 49,
|
||||||
|
"name": {
|
||||||
|
"uz": "Inventar",
|
||||||
|
"en": "Inventar",
|
||||||
|
"ru": "Inventar"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 51,
|
||||||
|
"name": {
|
||||||
|
"ru": "\u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434\u044b",
|
||||||
|
"en": "\u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434\u044b",
|
||||||
|
"uz": "\u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0440\u0430\u0441\u0445\u043e\u0434\u044b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 55,
|
||||||
|
"name": {
|
||||||
|
"ru": "Qurilish montaj ishlari",
|
||||||
|
"en": "Qurilish montaj ishlari",
|
||||||
|
"uz": "Qurilish montaj ishlari"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 78,
|
||||||
|
"name": {
|
||||||
|
"uz": "NARYAD",
|
||||||
|
"en": "NARYAD",
|
||||||
|
"ru": "NARYAD"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 83,
|
||||||
|
"name": {
|
||||||
|
"uz": "OFIS INVENTARLARI",
|
||||||
|
"en": "OFIS INVENTARLARI",
|
||||||
|
"ru": "OFIS INVENTARLARI"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 148,
|
||||||
|
"name": {
|
||||||
|
"uz": "Texnika xizmati",
|
||||||
|
"en": "Texnika xizmati",
|
||||||
|
"ru": "Texnika xizmati"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 149,
|
||||||
|
"name": {
|
||||||
|
"uz": "Marketing xizmati",
|
||||||
|
"en": "Marketing xizmati",
|
||||||
|
"ru": "Marketing xizmati"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"message": {
|
||||||
|
"uz": "Muvaffaqiyatli!",
|
||||||
|
"ru": "\u0423\u0441\u043f\u0435\u0448\u043d\u043e!",
|
||||||
|
"en": "Success!",
|
||||||
|
"tr": "Ba\u015far\u0131l\u0131!"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import json, requests
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from core.apps.products.models import Folder, SubFolder
|
||||||
|
|
||||||
|
|
||||||
|
def get_product_sub_folder(folder_id):
|
||||||
|
url = f'https://backend.app.uyqur.uz/main/category/view/subcategory?category_id={folder_id}'
|
||||||
|
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MTgzMzg2OSwiZXhwIjoxNzYxOTIwMjY5LCJuYmYiOjE3NjE4MzM4NjksImp0aSI6IjZSQWE1RzlyT0pGbXF1T2kiLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.ACT7oxl-A2eit_bzxeal2jF_xLa0klFObNBpp1HuheE"
|
||||||
|
|
||||||
|
res = requests.get(url, headers={"Authorization": f"Bearer {token}"})
|
||||||
|
|
||||||
|
if res.status_code == 200:
|
||||||
|
return res.json()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
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']:
|
||||||
|
folder_id = item['id']
|
||||||
|
folder, created = Folder.objects.get_or_create(name=item['name']['uz'])
|
||||||
|
sub_folders = get_product_sub_folder(folder_id)
|
||||||
|
if sub_folders:
|
||||||
|
for sub_folder in sub_folders['data']:
|
||||||
|
SubFolder.objects.get_or_create(name=sub_folder['name']['uz'], folder=folder)
|
||||||
|
self.stdout.write("Folderlar qoshildi")
|
||||||
55
core/apps/projects/data/project_folder.json
Normal file
55
core/apps/projects/data/project_folder.json
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"projects": [],
|
||||||
|
"project_folders": [
|
||||||
|
{
|
||||||
|
"id": 131,
|
||||||
|
"name": "Mezbon",
|
||||||
|
"color": "#F79009",
|
||||||
|
"projects_count": 9,
|
||||||
|
"percent": 9.51,
|
||||||
|
"total_amount": 18824049921.63,
|
||||||
|
"spend_amount": 33197807945.95,
|
||||||
|
"prediction_amount": 33197807945.95,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "16.03.2027",
|
||||||
|
"is_archived": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 89,
|
||||||
|
"name": "Mavrid",
|
||||||
|
"color": "#1E90FF",
|
||||||
|
"projects_count": 4,
|
||||||
|
"percent": 13.94,
|
||||||
|
"total_amount": 5025316534.38,
|
||||||
|
"spend_amount": 80865978602.1,
|
||||||
|
"prediction_amount": 80865978602.1,
|
||||||
|
"start_date": "01.04.2024",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "21.12.2028",
|
||||||
|
"is_archived": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 575,
|
||||||
|
"name": "papka 1",
|
||||||
|
"color": null,
|
||||||
|
"projects_count": 0,
|
||||||
|
"percent": 0,
|
||||||
|
"total_amount": 0,
|
||||||
|
"spend_amount": 0,
|
||||||
|
"prediction_amount": 0,
|
||||||
|
"start_date": null,
|
||||||
|
"due_date": null,
|
||||||
|
"prediction_date": null,
|
||||||
|
"is_archived": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"uz": "Muvaffaqiyatli!",
|
||||||
|
"ru": "Успешно!",
|
||||||
|
"en": "Success!",
|
||||||
|
"tr": "Başarılı!"
|
||||||
|
}
|
||||||
|
}
|
||||||
339
core/apps/projects/data/projects.json
Normal file
339
core/apps/projects/data/projects.json
Normal file
@@ -0,0 +1,339 @@
|
|||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 89,
|
||||||
|
"name": "Mavrid",
|
||||||
|
"color": "#1E90FF",
|
||||||
|
"percent": 13.94,
|
||||||
|
"total_amount": 5025316534.38,
|
||||||
|
"spend_amount": 80865978602.1,
|
||||||
|
"prediction_amount": 80865978602.1,
|
||||||
|
"projects_count": 4,
|
||||||
|
"start_date": "01.04.2024",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"projects": [
|
||||||
|
{
|
||||||
|
"id": 332,
|
||||||
|
"name": "A BLOK",
|
||||||
|
"status": "process",
|
||||||
|
"percent": 55.76,
|
||||||
|
"start_date": "01.04.2024",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "21.12.2028",
|
||||||
|
"total_amount": 1354794239.61,
|
||||||
|
"prediction_amount": 20216494650.52,
|
||||||
|
"spend_amount": 20216494650.52,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 376,
|
||||||
|
"name": "B BLOK",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "03.07.2025",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"total_amount": 1835261147.38,
|
||||||
|
"prediction_amount": 20216494650.52,
|
||||||
|
"spend_amount": 20216494650.52,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 377,
|
||||||
|
"name": "C BLOK",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "01.04.2024",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"total_amount": 1835261147.38,
|
||||||
|
"prediction_amount": 20216494650.52,
|
||||||
|
"spend_amount": 20216494650.52,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 438,
|
||||||
|
"name": "Ushbu loyihada ishlatilgan texnikalar",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "01.04.2024",
|
||||||
|
"due_date": "30.04.2026",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"total_amount": 0,
|
||||||
|
"prediction_amount": 20216494650.52,
|
||||||
|
"spend_amount": 20216494650.52,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 1754932443
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 131,
|
||||||
|
"name": "Mezbon",
|
||||||
|
"color": "#F79009",
|
||||||
|
"percent": 9.51,
|
||||||
|
"total_amount": 18824049921.63,
|
||||||
|
"spend_amount": 33197807945.95,
|
||||||
|
"prediction_amount": 33197807945.95,
|
||||||
|
"projects_count": 9,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"projects": [
|
||||||
|
{
|
||||||
|
"id": 307,
|
||||||
|
"name": "Blok №1",
|
||||||
|
"status": "process",
|
||||||
|
"percent": 27.92,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "30.04.2026",
|
||||||
|
"total_amount": 5422185157.58,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 375,
|
||||||
|
"name": "Blok №2",
|
||||||
|
"status": "process",
|
||||||
|
"percent": 41.03,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "19.11.2026",
|
||||||
|
"total_amount": 2367992764,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 382,
|
||||||
|
"name": "Blok №3",
|
||||||
|
"status": "process",
|
||||||
|
"percent": 16.67,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "27.09.2026",
|
||||||
|
"total_amount": 2269876000.05,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 380,
|
||||||
|
"name": "Blok №4",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "16.03.2027",
|
||||||
|
"total_amount": 2190999000,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 381,
|
||||||
|
"name": "Blok №5",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "16.03.2027",
|
||||||
|
"total_amount": 2190999000,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 378,
|
||||||
|
"name": "Blok №6",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "16.03.2027",
|
||||||
|
"total_amount": 2190999000,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 379,
|
||||||
|
"name": "Blok №7",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "16.03.2027",
|
||||||
|
"total_amount": 2190999000,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 7
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 407,
|
||||||
|
"name": "Ushbu loyihada ishlagan texnikalar",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"total_amount": 0,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 8
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 657,
|
||||||
|
"name": "Ushbu loyihadagi boshqa mahsulotlar",
|
||||||
|
"status": "planning",
|
||||||
|
"percent": 0,
|
||||||
|
"start_date": "14.02.2025",
|
||||||
|
"due_date": "14.02.2028",
|
||||||
|
"prediction_date": "30.10.2025",
|
||||||
|
"total_amount": 0,
|
||||||
|
"prediction_amount": 3688645327.33,
|
||||||
|
"spend_amount": 3688645327.33,
|
||||||
|
"currency": {
|
||||||
|
"id": 1,
|
||||||
|
"name": {
|
||||||
|
"ru": "Узбекский сум",
|
||||||
|
"uz": "O'zbek so'mi"
|
||||||
|
},
|
||||||
|
"symbol": "UZS",
|
||||||
|
"icon": "https://backend.app.uyqur.uz/public/upload/image/YZfoihq4VHMSHaZziQlp.webp"
|
||||||
|
},
|
||||||
|
"is_archived": false,
|
||||||
|
"order": 1761819015
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"message": {
|
||||||
|
"uz": "Muvaffaqiyatli!",
|
||||||
|
"ru": "Успешно!",
|
||||||
|
"en": "Success!",
|
||||||
|
"tr": "Başarılı!"
|
||||||
|
}
|
||||||
|
}
|
||||||
94
core/apps/projects/management/commands/import_project.py
Normal file
94
core/apps/projects/management/commands/import_project.py
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
from core.apps.projects.models import ProjectFolder, Project, ProjectLocation
|
||||||
|
from core.apps.wherehouse.models import WhereHouse
|
||||||
|
from core.apps.finance.models import CashTransaction
|
||||||
|
from core.apps.shared.models import Region, District
|
||||||
|
from core.apps.accounts.models import User
|
||||||
|
|
||||||
|
|
||||||
|
def get_project_data(project_id):
|
||||||
|
url = f"https://backend.app.uyqur.uz/main/project/view?id={project_id}"
|
||||||
|
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MTgzMzg2OSwiZXhwIjoxNzYxOTIwMjY5LCJuYmYiOjE3NjE4MzM4NjksImp0aSI6IjZSQWE1RzlyT0pGbXF1T2kiLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.ACT7oxl-A2eit_bzxeal2jF_xLa0klFObNBpp1HuheE"
|
||||||
|
|
||||||
|
response = requests.get(url, headers={"Authorization": f"Bearer {token}"})
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json().get("data")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
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 folder in data["data"]:
|
||||||
|
folder_name = folder["name"]
|
||||||
|
folder_projects = folder["projects"]
|
||||||
|
|
||||||
|
project_folder = ProjectFolder.objects.filter(name=folder_name).first()
|
||||||
|
if not project_folder:
|
||||||
|
project_folder = ProjectFolder.objects.create(name=folder_name)
|
||||||
|
|
||||||
|
statuses = {
|
||||||
|
"process": "IN_PROGRESS",
|
||||||
|
"planning": "PLANNED",
|
||||||
|
}
|
||||||
|
|
||||||
|
for project_meta in folder_projects:
|
||||||
|
start_date = datetime.strptime(project_meta["start_date"], "%d.%m.%Y")
|
||||||
|
end_date = datetime.strptime(project_meta["due_date"], "%d.%m.%Y")
|
||||||
|
|
||||||
|
project_data = get_project_data(project_meta["id"])
|
||||||
|
if not project_data:
|
||||||
|
self.stdout.write(self.style.ERROR(f"{project_meta['name']} topilmadi"))
|
||||||
|
continue
|
||||||
|
|
||||||
|
cash_names = [c["name"] for c in project_data.get("cashs", [])]
|
||||||
|
cash_qs = CashTransaction.objects.filter(name__in=cash_names)
|
||||||
|
|
||||||
|
warehouse_names = [w["name"] for w in project_data.get("warehouses", [])]
|
||||||
|
warehouse_qs = WhereHouse.objects.filter(name__in=warehouse_names)
|
||||||
|
|
||||||
|
manager_names = [u["full_name"] for u in project_data["project_users"] if u["type"] == "manager"]
|
||||||
|
foreman_names = [u["full_name"] for u in project_data["project_users"] if u["type"] == "foreman"]
|
||||||
|
participant_names = [u["full_name"] for u in project_data["project_users"] if u["type"] == "participant"]
|
||||||
|
|
||||||
|
boss_qs = User.objects.filter(full_name__in=manager_names)
|
||||||
|
foreman_qs = User.objects.filter(full_name__in=foreman_names)
|
||||||
|
other_qs = User.objects.filter(full_name__in=participant_names)
|
||||||
|
|
||||||
|
project_obj, created = Project.objects.update_or_create(
|
||||||
|
name=project_data["name"],
|
||||||
|
defaults={
|
||||||
|
"folder": project_folder,
|
||||||
|
"currency": project_data["currency"]["symbol"].lower(),
|
||||||
|
"status": statuses.get(project_data["status"]),
|
||||||
|
"is_archive": project_data.get("is_archived", False),
|
||||||
|
"start_date": start_date,
|
||||||
|
"end_date": end_date,
|
||||||
|
"benifit_plan": project_data['prediction_amount'],
|
||||||
|
"area": project_data.get("area", 0),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
project_obj.cash_transaction.set(cash_qs)
|
||||||
|
project_obj.wherehouse.set(warehouse_qs)
|
||||||
|
project_obj.boss.set(boss_qs)
|
||||||
|
project_obj.foreman.set(foreman_qs)
|
||||||
|
project_obj.other_members.set(other_qs)
|
||||||
|
|
||||||
|
project_obj.save()
|
||||||
|
|
||||||
|
msg = "Yaratildi" if created else "Yangilandi"
|
||||||
|
self.stdout.write(self.style.SUCCESS(f"{project_obj.name} → {msg}"))
|
||||||
|
|
||||||
|
self.stdout.write(self.style.SUCCESS("✅ Barcha projectlar muvaffaqiyatli qo'shildi!"))
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from core.apps.projects.models import ProjectFolder
|
||||||
|
|
||||||
|
|
||||||
|
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']['project_folders']:
|
||||||
|
ProjectFolder.objects.get_or_create(
|
||||||
|
name=item['name'],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stdout.write("Project Folderlar qo'shildi")
|
||||||
|
|
||||||
Reference in New Issue
Block a user