From d9ac198bad79c0de7df23cbccadcda48c09c72d6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 25 Feb 2026 14:23:38 +0530 Subject: [PATCH] fix: reposting creation slow for GL entries --- .../repost_item_valuation.json | 5 +- .../repost_item_valuation.py | 66 +++++++++++++------ .../stock_reposting_settings.json | 20 +++++- .../stock_reposting_settings.py | 1 + 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json index 05d302dc4f1..e1ae6d00cd9 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json @@ -237,7 +237,8 @@ "fieldname": "reposting_reference", "fieldtype": "Data", "label": "Reposting Reference", - "read_only": 1 + "read_only": 1, + "search_index": 1 }, { "default": "0", @@ -252,7 +253,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2025-12-24 14:59:15.512898", + "modified": "2026-02-25 14:22:21.681549", "modified_by": "Administrator", "module": "Stock", "name": "Repost Item Valuation", diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 7be0b09169e..d487fa091ed 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -470,7 +470,15 @@ def repost_gl_entries(doc): repost_affected_transaction = get_affected_transactions(doc) transactions = directly_dependent_transactions + list(repost_affected_transaction) - if doc.based_on == "Item and Warehouse" and not doc.repost_only_accounting_ledgers: + enable_separate_reposting_for_gl = frappe.db.get_single_value( + "Stock Reposting Settings", "enable_separate_reposting_for_gl" + ) + + if ( + enable_separate_reposting_for_gl + and doc.based_on == "Item and Warehouse" + and not doc.repost_only_accounting_ledgers + ): make_reposting_for_accounting_ledgers( transactions, doc.company, @@ -671,25 +679,43 @@ def execute_repost_item_valuation(): def make_reposting_for_accounting_ledgers(transactions, company, repost_doc): + reposting_map = get_existing_reposting_only_gl_entries(repost_doc.name) + for voucher_type, voucher_no in transactions: - if frappe.db.exists( - "Repost Item Valuation", - { - "voucher_type": voucher_type, - "voucher_no": voucher_no, - "docstatus": 1, - "reposting_reference": repost_doc.name, - "repost_only_accounting_ledgers": 1, - "status": "Queued", - }, - ): + if reposting_map.get((voucher_type, voucher_no)): continue - new_repost_doc = frappe.new_doc("Repost Item Valuation") - new_repost_doc.company = company - new_repost_doc.voucher_type = voucher_type - new_repost_doc.voucher_no = voucher_no - new_repost_doc.repost_only_accounting_ledgers = 1 - new_repost_doc.reposting_reference = repost_doc.name - new_repost_doc.flags.ignore_permissions = True - new_repost_doc.submit() + try: + new_repost_doc = frappe.new_doc("Repost Item Valuation") + new_repost_doc.company = company + new_repost_doc.voucher_type = voucher_type + new_repost_doc.voucher_no = voucher_no + new_repost_doc.repost_only_accounting_ledgers = 1 + new_repost_doc.reposting_reference = repost_doc.name + new_repost_doc.flags.ignore_permissions = True + new_repost_doc.submit() + except Exception: + pass + + +def get_existing_reposting_only_gl_entries(reposting_reference): + existing_reposting = frappe.get_all( + "Repost Item Valuation", + filters={ + "reposting_reference": reposting_reference, + "docstatus": 1, + "status": "Queued", + "repost_only_accounting_ledgers": 1, + }, + fields=["reposting_reference", "voucher_type", "voucher_no"], + ) + + if not existing_reposting: + return frappe._dict() + + reposting_map = {} + for d in existing_reposting: + key = (d.voucher_type, d.voucher_no) + reposting_map[key] = d.reposting_reference + + return reposting_map diff --git a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json index 410c0cee62d..f72b50dc131 100644 --- a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json +++ b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json @@ -13,8 +13,11 @@ "end_time", "limits_dont_apply_on", "item_based_reposting", + "section_break_dxuf", "enable_parallel_reposting", "no_of_parallel_reposting", + "column_break_itvd", + "enable_separate_reposting_for_gl", "errors_notification_section", "notify_reposting_error_to_role" ], @@ -81,13 +84,28 @@ "fieldname": "no_of_parallel_reposting", "fieldtype": "Int", "label": "No of Parallel Reposting (Per Item)" + }, + { + "fieldname": "section_break_dxuf", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_itvd", + "fieldtype": "Column Break" + }, + { + "default": "0", + "depends_on": "item_based_reposting", + "fieldname": "enable_separate_reposting_for_gl", + "fieldtype": "Check", + "label": "Enable Separate Reposting for GL" } ], "hide_toolbar": 1, "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2026-01-02 18:18:57.115176", + "modified": "2026-02-25 14:11:33.461173", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reposting Settings", diff --git a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.py b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.py index 7924c9042c0..40f9f1f6d69 100644 --- a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.py +++ b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.py @@ -17,6 +17,7 @@ class StockRepostingSettings(Document): from frappe.types import DF enable_parallel_reposting: DF.Check + enable_separate_reposting_for_gl: DF.Check end_time: DF.Time | None item_based_reposting: DF.Check limit_reposting_timeslot: DF.Check