From 5d8941843f52d8c28efc5b0f0d8b25ac2adbde54 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Mon, 8 Sep 2025 18:11:51 +0400 Subject: [PATCH] stock_rbnb fix --- jey_erp/hooks.py | 7 ++-- jey_erp/patches/purchase_receipt.py | 52 +++++------------------------ 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/jey_erp/hooks.py b/jey_erp/hooks.py index b6af8d1..d7ec66c 100644 --- a/jey_erp/hooks.py +++ b/jey_erp/hooks.py @@ -47,7 +47,10 @@ doc_events = { "jey_erp.custom.sales_order_vat.set_vat_fields_permissions" ], "before_save": "jey_erp.custom.sales_order_vat.set_vat_fields_permissions" - } + }, + "Purchase Receipt": { + "before_submit": "jey_erp.patches.purchase_receipt.disable_stock_rbnb_entries" + } } after_migrate = "jey_erp.hooks.after_migrate_combined" @@ -60,8 +63,6 @@ def after_migrate_combined(): show_item_tax_template_in_sales_invoice() from jey_erp.custom.vat_calculations import patch_sales_documents patch_sales_documents() - from jey_erp.patches.purchase_receipt import stock_received_but_not_billed_skip_patch - stock_received_but_not_billed_skip_patch() fixtures = [ diff --git a/jey_erp/patches/purchase_receipt.py b/jey_erp/patches/purchase_receipt.py index 3b6c104..fc7aeef 100644 --- a/jey_erp/patches/purchase_receipt.py +++ b/jey_erp/patches/purchase_receipt.py @@ -1,49 +1,13 @@ import frappe -from erpnext.stock.doctype.purchase_receipt.purchase_receipt import PurchaseReceipt -from erpnext.accounts.general_ledger import process_gl_map -from erpnext.accounts.utils import get_account_currency -from frappe.utils import flt -from frappe import _ -def stock_received_but_not_billed_skip_patch(): - """Применяем monkey patch для Purchase Receipt""" - # Сохраняем оригинальный метод - original_make_item_gl_entries = PurchaseReceipt.make_item_gl_entries +def disable_stock_rbnb_entries(doc, method): + """Отключаем создание GL entries для stock received but not billed""" - def patched_make_item_gl_entries(self, gl_entries, warehouse_account=None): - # Весь оригинальный код метода, но с изменением stock_asset_rbnb = None - from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import get_purchase_document_details - - provisional_accounting_for_non_stock_items = frappe.db.get_value( - "Company", self.company, "enable_provisional_accounting_for_non_stock_items" - ) - - exchange_rate_map, net_rate_map = get_purchase_document_details(self) - - def validate_account(account_type): - frappe.throw(_("{0} account not found while submitting purchase receipt").format(account_type)) - - # ГЛАВНОЕ ИЗМЕНЕНИЕ: Заменяем проблемную логику - stock_asset_rbnb = None # Отключаем проверку счета - - # Остальная логика остается как в оригинале... - stock_items = self.get_stock_items() - warehouse_with_no_account = [] - - for d in self.get("items"): - if (provisional_accounting_for_non_stock_items - and d.item_code not in stock_items - and flt(d.qty) - and d.get("provisional_expense_account") - and not d.is_fixed_asset): - self.add_provisional_gl_entry(d, gl_entries, self.posting_date, d.get("provisional_expense_account")) - - # Пропускаем создание GL entries если stock_asset_rbnb = None - elif flt(d.qty) and (flt(d.valuation_rate) or self.is_return) and stock_asset_rbnb is not None: - # Оригинальная логика создания GL entries - pass - + original_make_item_gl_entries = doc.make_item_gl_entries + + def patched_make_item_gl_entries(gl_entries, warehouse_account=None): + # Просто ничего не делаем - полностью пропускаем GL entries + frappe.msgprint("GL entries для Purchase Receipt отключены", alert=True) return - # Заменяем метод - PurchaseReceipt.make_item_gl_entries = patched_make_item_gl_entries \ No newline at end of file + doc.make_item_gl_entries = patched_make_item_gl_entries \ No newline at end of file