diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index dabb9fde35d..c1d0aea7ae1 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -111,17 +111,15 @@ class AccountingDimension(Document): def make_dimension_in_accounting_doctypes(doc, doclist=None): if not doclist: doclist = get_doctypes_with_dimensions() - doc_count = len(get_accounting_dimensions()) count = 0 - repostable_doctypes = get_allowed_types_from_settings() + repostable_doctypes = get_allowed_types_from_settings(child_doc=True) for doctype in doclist: if (doc_count + 1) % 2 == 0: insert_after_field = "dimension_col_break" else: insert_after_field = "accounting_dimensions_section" - df = { "fieldname": doc.fieldname, "label": doc.label, diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py index aec26b280c4..37863036492 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py @@ -5,6 +5,7 @@ import inspect import frappe from frappe import _, qb +from frappe.desk.form.linked_with import get_child_tables_of_doctypes from frappe.model.document import Document from frappe.utils.data import comma_and @@ -208,13 +209,29 @@ def start_repost(account_repost_doc=str) -> None: doc.make_gl_entries() -def get_allowed_types_from_settings(): - return [ +def get_allowed_types_from_settings(child_doc: bool = False): + repost_docs = [ x.document_type for x in frappe.db.get_all( "Repost Allowed Types", filters={"allowed": True}, fields=["distinct(document_type)"] ) ] + result = repost_docs + + if repost_docs and child_doc: + result.extend(get_child_docs(repost_docs)) + + return result + + +def get_child_docs(doc: list) -> list: + child_doc = [] + doc = get_child_tables_of_doctypes(doc) + for child_list in doc.values(): + for child in child_list: + if child.get("child_table"): + child_doc.append(child["child_table"]) + return child_doc def validate_docs_for_deferred_accounting(sales_docs, purchase_docs): diff --git a/erpnext/accounts/doctype/repost_accounting_ledger_settings/repost_accounting_ledger_settings.py b/erpnext/accounts/doctype/repost_accounting_ledger_settings/repost_accounting_ledger_settings.py index 14a070dc464..637234fea1e 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger_settings/repost_accounting_ledger_settings.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger_settings/repost_accounting_ledger_settings.py @@ -1,9 +1,14 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document +from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( + get_accounting_dimensions, +) +from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import get_child_docs + class RepostAccountingLedgerSettings(Document): # begin: auto-generated types @@ -17,6 +22,24 @@ class RepostAccountingLedgerSettings(Document): from erpnext.accounts.doctype.repost_allowed_types.repost_allowed_types import RepostAllowedTypes allowed_types: DF.Table[RepostAllowedTypes] - # end: auto-generated types - pass + # end: auto-generated types + def validate(self): + self.update_property_for_accounting_dimension() + + def update_property_for_accounting_dimension(self): + doctypes = [entry.document_type for entry in self.allowed_types if entry.allowed] + if not doctypes: + return + doctypes += get_child_docs(doctypes) + + set_allow_on_submit_for_dimension_fields(doctypes) + + +def set_allow_on_submit_for_dimension_fields(doctypes): + for dt in doctypes: + meta = frappe.get_meta(dt) + for dimension in get_accounting_dimensions(): + df = meta.get_field(dimension) + if df and not df.allow_on_submit: + frappe.db.set_value("Custom Field", dt + "-" + dimension, "allow_on_submit", 1) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 170c02fe587..532c5f1b2a4 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -357,7 +357,7 @@ execute:frappe.db.set_single_value("Buying Settings", "project_update_frequency" execute:frappe.db.set_default("date_format", frappe.db.get_single_value("System Settings", "date_format")) erpnext.patches.v14_0.update_total_asset_cost_field erpnext.patches.v15_0.create_advance_payment_status -erpnext.patches.v15_0.allow_on_submit_dimensions_for_repostable_doctypes +erpnext.patches.v15_0.allow_on_submit_dimensions_for_repostable_doctypes #2025-06-19 erpnext.patches.v14_0.create_accounting_dimensions_in_reconciliation_tool erpnext.patches.v14_0.update_flag_for_return_invoices #2024-03-22 erpnext.patches.v15_0.create_accounting_dimensions_in_payment_request diff --git a/erpnext/patches/v15_0/allow_on_submit_dimensions_for_repostable_doctypes.py b/erpnext/patches/v15_0/allow_on_submit_dimensions_for_repostable_doctypes.py index e75610d0a53..dddeae328c7 100644 --- a/erpnext/patches/v15_0/allow_on_submit_dimensions_for_repostable_doctypes.py +++ b/erpnext/patches/v15_0/allow_on_submit_dimensions_for_repostable_doctypes.py @@ -9,6 +9,6 @@ from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger def execute(): - for dt in get_allowed_types_from_settings(): + for dt in get_allowed_types_from_settings(child_doc=True): for dimension in get_accounting_dimensions(): frappe.db.set_value("Custom Field", dt + "-" + dimension, "allow_on_submit", 1)