From 8f414edaf6590de183509f2581c481e5276360fb Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Tue, 5 Aug 2025 21:25:56 +0400 Subject: [PATCH] updated fixtures for item and item group --- taxes_az/auth.py | 10 +- taxes_az/fixtures/item.json | 542 ++++++++++++++++++++++++++++++ taxes_az/fixtures/item_group.json | 28 ++ taxes_az/hooks.py | 12 + 4 files changed, 587 insertions(+), 5 deletions(-) create mode 100644 taxes_az/fixtures/item.json create mode 100644 taxes_az/fixtures/item_group.json diff --git a/taxes_az/auth.py b/taxes_az/auth.py index 95caffd..f511aff 100644 --- a/taxes_az/auth.py +++ b/taxes_az/auth.py @@ -98,7 +98,7 @@ def check_recent_activity(asan_login_name=None): return False # В случае ошибки считаем, что активности не было @frappe.whitelist() -def renew_token(asan_login_name=None, retry_count=0, force=False): +def renew_token(asan_login_name=None, force=False, retry_count=0): """Renews the main token with optimized performance and error handling""" try: # Получаем документ Asan Login @@ -118,7 +118,7 @@ def renew_token(asan_login_name=None, retry_count=0, force=False): asan_login_name = default_settings[0].name # Проверяем наличие активности, если force=False - if not check_recent_activity(asan_login_name): + if not force and not check_recent_activity(asan_login_name): frappe.logger().info(f"Token renewal skipped due to inactivity for {asan_login_name}") return {"success": True, "message": "Token renewal skipped due to inactivity"} @@ -194,7 +194,7 @@ def renew_token(asan_login_name=None, retry_count=0, force=False): # Экспоненциальная задержка между попытками wait_time = (2 ** retry_count) * (0.5 + random.random()) time.sleep(wait_time) - return renew_token(asan_login_name, retry_count + 1) + return renew_token(asan_login_name, force, retry_count + 1) # ← ИСПРАВЛЕН ПОРЯДОК frappe.log_error( f"Failed with status {response.status_code}: {response.text[:200]}", @@ -207,7 +207,7 @@ def renew_token(asan_login_name=None, retry_count=0, force=False): if retry_count < MAX_RETRY_COUNT: wait_time = (2 ** retry_count) * (0.5 + random.random()) time.sleep(wait_time) - return renew_token(asan_login_name, retry_count + 1) + return renew_token(asan_login_name, force, retry_count + 1) # ← ИСПРАВЛЕН ПОРЯДОК # Check if the error is HTTP 401 or 500 if hasattr(e, 'response'): @@ -236,7 +236,7 @@ def renew_token(asan_login_name=None, retry_count=0, force=False): f"Token Renewal for {asan_login_name}" ) return {"success": False, "message": "An unknown error occurred, please try again in a few minutes."} - + @frappe.whitelist() def setup_token_renewal(): """Настраивает задание планировщика для обновления токенов""" diff --git a/taxes_az/fixtures/item.json b/taxes_az/fixtures/item.json new file mode 100644 index 0000000..992e0f7 --- /dev/null +++ b/taxes_az/fixtures/item.json @@ -0,0 +1,542 @@ +[ + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": null, + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "Dizel yanacağı", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 0, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "MT25071015987100001", + "item_defaults": [], + "item_group": "All Item Groups", + "item_name": "Dizel yanacağı", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-07-23 19:27:16.025311", + "name": "MT25071015987100001", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Nos", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Nos" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + }, + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": "Azerbaijan", + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "JE000001", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 1, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "JE000001", + "item_defaults": [], + "item_group": "Yanacaq növləri", + "item_name": "Avtomobil benzini (Aİ-92)", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-08-05 20:48:39.671600", + "name": "JE000001", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Litre", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Litre" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + }, + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": "Azerbaijan", + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "Avtomobil benzini (Aİ-95)", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 1, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "JE000002", + "item_defaults": [], + "item_group": "Yanacaq növləri", + "item_name": "Avtomobil benzini (Aİ-95)", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-08-05 20:49:46.477107", + "name": "JE000002", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Litre", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Litre" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + }, + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": "Azerbaijan", + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "Avtomobil benzini (Aİ-95)", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 1, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "JE000003", + "item_defaults": [], + "item_group": "Yanacaq növləri", + "item_name": "Avtomobil benzini (Aİ-80)", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-08-05 20:49:54.221350", + "name": "JE000003", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Litre", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Litre" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + }, + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": "Azerbaijan", + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "Avtomobil benzini (Aİ-95)", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 1, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "JE000004", + "item_defaults": [], + "item_group": "Yanacaq növləri", + "item_name": "Dizel yanacağı", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-08-05 20:50:03.751877", + "name": "JE000004", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Litre", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Litre" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + }, + { + "allow_alternative_item": 0, + "allow_negative_stock": 0, + "asset_category": null, + "asset_naming_series": null, + "attributes": [], + "auto_create_assets": 0, + "barcodes": [], + "batch_number_series": null, + "brand": null, + "country_of_origin": "Azerbaijan", + "create_new_batch": 0, + "customer": null, + "customer_code": "", + "customer_items": [], + "customs_tariff_number": null, + "default_bom": null, + "default_item_manufacturer": null, + "default_manufacturer_part_no": null, + "default_material_request_type": "Purchase", + "delivered_by_supplier": 0, + "description": "Avtomobil benzini (Aİ-95)", + "disabled": 0, + "docstatus": 0, + "doctype": "Item", + "enable_deferred_expense": 0, + "enable_deferred_revenue": 0, + "end_of_life": "2099-12-31", + "grant_commission": 1, + "has_batch_no": 0, + "has_expiry_date": 0, + "has_serial_no": 0, + "has_variants": 0, + "image": null, + "include_item_in_manufacturing": 1, + "inspection_required_before_delivery": 0, + "inspection_required_before_purchase": 0, + "is_customer_provided_item": 0, + "is_fixed_asset": 0, + "is_grouped_asset": 0, + "is_purchase_item": 1, + "is_sales_item": 1, + "is_stock_item": 1, + "is_sub_contracted_item": 0, + "item_code": "JE000005", + "item_defaults": [], + "item_group": "Yanacaq növləri", + "item_name": "Maye qaz", + "last_purchase_rate": 0.0, + "lead_time_days": 0, + "max_discount": 0.0, + "min_order_qty": 0.0, + "modified": "2025-08-05 20:50:12.990478", + "name": "JE000005", + "naming_series": "STO-ITEM-.YYYY.-", + "no_of_months": 0, + "no_of_months_exp": 0, + "opening_stock": 0.0, + "over_billing_allowance": 0.0, + "over_delivery_receipt_allowance": 0.0, + "product_category": null, + "product_group_code": null, + "purchase_uom": null, + "quality_inspection_template": null, + "reorder_levels": [], + "retain_sample": 0, + "safety_stock": 0.0, + "sales_uom": null, + "sample_quantity": 0, + "serial_no_series": null, + "shelf_life_in_days": 0, + "standard_rate": 0.0, + "stock_uom": "Litre", + "supplier_items": [], + "taxes": [], + "total_projected_qty": 0.0, + "uoms": [ + { + "conversion_factor": 1.0, + "uom": "Litre" + } + ], + "valuation_method": "", + "valuation_rate": 0.0, + "variant_based_on": "Item Attribute", + "variant_of": null, + "warranty_period": null, + "weight_per_unit": 0.0, + "weight_uom": null + } +] \ No newline at end of file diff --git a/taxes_az/fixtures/item_group.json b/taxes_az/fixtures/item_group.json new file mode 100644 index 0000000..ef3a5b7 --- /dev/null +++ b/taxes_az/fixtures/item_group.json @@ -0,0 +1,28 @@ +[ + { + "docstatus": 0, + "doctype": "Item Group", + "image": null, + "is_group": 0, + "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ı", + "parent_item_group": "Neft Məhsulları", + "taxes": [] + }, + { + "docstatus": 0, + "doctype": "Item Group", + "image": null, + "is_group": 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", + "parent_item_group": "All Item Groups", + "taxes": [] + } +] \ No newline at end of file diff --git a/taxes_az/hooks.py b/taxes_az/hooks.py index 7d7a6af..709c085 100644 --- a/taxes_az/hooks.py +++ b/taxes_az/hooks.py @@ -12,6 +12,18 @@ fixtures = [ ["module", "=", "Taxes Az"] ] }, + { + "doctype": "Item", + "filters": [ + ["item_name", "in", ["Avtomobil benzini (Aİ-92)", "Avtomobil benzini (Aİ-95)", "Avtomobil benzini (Aİ-80)", "Dizel yanacağı", "Maye qaz"]] + ] + }, + { + "doctype": "Item Group", + "filters": [ + ["item_group_name", "in", ["Neft məhsulları", "Yanacaq növləri"]] + ] + }, { "doctype": "Main type of activity", "filters": []