now item group fixture is gone, and now python file creates those

This commit is contained in:
Ali 2025-09-03 21:50:54 +04:00
parent dc1b07c673
commit 024a5f53ee
3 changed files with 229 additions and 292 deletions

View File

@ -0,0 +1,227 @@
import frappe
from frappe import _
def create_item_groups():
"""
Создает Item Groups согласно фикстурам
"""
# Определяем возможные названия родительской группы
parent_names = ["All Item Groups", "Bütün Element Qrupları"]
parent_name = None
# Проверяем какое название родительской группы существует
for name in parent_names:
if frappe.db.exists("Item Group", name):
parent_name = name
break
if not parent_name:
print("Родительская группа не найдена. Используем 'All Item Groups'")
parent_name = "All Item Groups"
# Данные групп из фикстур
item_groups = [
{
"item_group_name": "Neft Məhsulları",
"is_group": 1,
"parent_item_group": parent_name
},
{
"item_group_name": "Yanacaq növləri",
"is_group": 0,
"parent_item_group": "Neft Məhsulları"
},
{
"item_group_name": "Faydalı qazıntılar",
"is_group": 1,
"parent_item_group": parent_name
},
{
"item_group_name": "Xam neft - ton",
"is_group": 0,
"parent_item_group": parent_name # В фикстуре old_parent не указан, используем корневую
},
{
"item_group_name": "Təbii qaz - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Filiz faydalı qazıntıları: bütün növ metallar - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Mişar daşları - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Üzlük daşları - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Seolit - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Barit - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Yüngül doldurucular üçün gillər - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Vulkan külü və pemza - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Kvars qumları - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Sement xammalı - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Duz - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Qiymətli və yarımqiymətli bəzək daşları - karat / qram",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Yodlu bromlu sular - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Mineral sular - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Bentonit gillər - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Kərpic-kirəmit gilləri - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Tikinti qumları - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Çınqıl xammalı - m³",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Gips, gəc - ton",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "İdman, mərc və lotoreya oyunları",
"is_group": 1,
"parent_item_group": parent_name
},
{
"item_group_name": "İdman və mərc oyunları",
"is_group": 0,
"parent_item_group": parent_name
},
{
"item_group_name": "Lotoreya oyunları",
"is_group": 0,
"parent_item_group": parent_name
}
]
created_count = 0
skipped_count = 0
for group_data in item_groups:
try:
# Проверяем, существует ли уже такая группа
if frappe.db.exists("Item Group", group_data["item_group_name"]):
print(f"Группа '{group_data['item_group_name']}' уже существует, пропускаем...")
skipped_count += 1
continue
# Создаем новую Item Group
item_group = frappe.new_doc("Item Group")
item_group.item_group_name = group_data["item_group_name"]
item_group.is_group = group_data["is_group"]
item_group.parent_item_group = group_data["parent_item_group"]
# Сохраняем документ
item_group.insert(ignore_permissions=True)
frappe.db.commit()
print(f"✓ Создана группа: {group_data['item_group_name']}")
created_count += 1
except Exception as e:
print(f"✗ Ошибка при создании группы '{group_data['item_group_name']}': {str(e)}")
continue
print(f"\nРезультат:")
print(f"Создано новых групп: {created_count}")
print(f"Пропущено существующих: {skipped_count}")
print(f"Всего обработано: {len(item_groups)}")
def delete_all_created_groups():
"""
Функция для удаления всех созданных групп (для отката)
ВНИМАНИЕ: Используйте осторожно!
"""
group_names = [
"Neft Məhsulları", "Yanacaq növləri", "Faydalı qazıntılar",
"Xam neft - ton", "Təbii qaz - m³",
"Filiz faydalı qazıntıları: bütün növ metallar - ton",
"Mişar daşları - m³", "Üzlük daşları - m³", "Seolit - ton",
"Barit - ton", "Yüngül doldurucular üçün gillər - m³",
"Vulkan külü və pemza - m³", "Kvars qumları - ton",
"Sement xammalı - ton", "Duz - ton",
"Qiymətli və yarımqiymətli bəzək daşları - karat / qram",
"Yodlu bromlu sular - m³", "Mineral sular - m³",
"Bentonit gillər - ton", "Kərpic-kirəmit gilləri - m³",
"Tikinti qumları - m³", "Çınqıl xammalı - m³",
"Gips, gəc - ton", "İdman, mərc və lotoreya oyunları",
"İdman və mərc oyunları", "Lotoreya oyunları"
]
deleted_count = 0
for group_name in group_names:
try:
if frappe.db.exists("Item Group", group_name):
frappe.delete_doc("Item Group", group_name)
print(f"✓ Удалена группа: {group_name}")
deleted_count += 1
except Exception as e:
print(f"✗ Ошибка при удалении группы '{group_name}': {str(e)}")
frappe.db.commit()
print(f"\nУдалено групп: {deleted_count}")
# Основная функция для запуска
if __name__ == "__main__":
create_item_groups()

View File

@ -1,292 +0,0 @@
[
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 1,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Neft Məhsulları",
"modified": "2025-08-05 19:50:16.068055",
"name": "Neft Məhsulları",
"old_parent": "All Item Groups",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Yanacaq növləri",
"modified": "2025-08-05 19:51:16.965899",
"name": "Yanacaq növləri",
"old_parent": "Neft Məhsulları",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 1,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Faydalı qazıntılar",
"name": "Faydalı qazıntılar",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Xam neft - ton",
"name": "Xam neft - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Təbii qaz - m³",
"name": "Təbii qaz - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Filiz faydalı qazıntıları: bütün növ metallar - ton",
"name": "Filiz faydalı qazıntıları: bütün növ metallar - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Mişar daşları - m³",
"name": "Mişar daşları - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Üzlük daşları - m³",
"name": "Üzlük daşları - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Seolit - ton",
"name": "Seolit - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Barit - ton",
"name": "Barit - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Yüngül doldurucular üçün gillər - m³",
"name": "Yüngül doldurucular üçün gillər - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Vulkan külü və pemza - m³",
"name": "Vulkan külü və pemza - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Kvars qumları - ton",
"name": "Kvars qumları - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Sement xammalı - ton",
"name": "Sement xammalı - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Duz - ton",
"name": "Duz - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Qiymətli və yarımqiymətli bəzək daşları - karat / qram",
"name": "Qiymətli və yarımqiymətli bəzək daşları - karat / qram",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Yodlu bromlu sular - m³",
"name": "Yodlu bromlu sular - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Mineral sular - m³",
"name": "Mineral sular - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Bentonit gillər - ton",
"name": "Bentonit gillər - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Kərpic-kirəmit gilləri - m³",
"name": "Kərpic-kirəmit gilləri - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Tikinti qumları - m³",
"name": "Tikinti qumları - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": ınqıl xammalı - m³",
"name": ınqıl xammalı - m³",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Gips, gəc - ton",
"name": "Gips, gəc - ton",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 1,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "İdman, mərc və lotoreya oyunları",
"name": "İdman, mərc və lotoreya oyunları",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "İdman və mərc oyunları",
"name": "İdman və mərc oyunları",
"taxes": []
},
{
"docstatus": 0,
"doctype": "Item Group",
"image": null,
"is_group": 0,
"is_standard": 1,
"item_group_defaults": [],
"item_group_name": "Lotoreya oyunları",
"name": "Lotoreya oyunları",
"taxes": []
}
]

View File

@ -34,6 +34,8 @@ fixtures = [
} }
] ]
after_migrate = "taxes_az.create_item_group.create_item_groups"
doctype_js = { doctype_js = {
"XML Mapping Tool": [ "XML Mapping Tool": [
"public/js/xml_mapping/xml_parser.js", "public/js/xml_mapping/xml_parser.js",