From d06a46ae8516dddff98e0cbff21766c314a52333 Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Thu, 5 Feb 2026 18:24:26 +0530 Subject: [PATCH] feat(accounts): expand Journal Entry Template to support dimensions and party (#51621) * feat(accounts): expand Journal Entry Template to support dimensions and party * fix: do not update standard row values (cherry picked from commit ef44528ba5d43e83f167a502734a628453b843f3) --- .../doctype/journal_entry/journal_entry.js | 16 +++++- .../journal_entry_template.js | 26 ++++++++++ .../journal_entry_template.py | 25 +++++++++- .../journal_entry_template_account.json | 49 +++++++++++++++++-- .../journal_entry_template_account.py | 4 ++ erpnext/hooks.py | 1 + erpnext/patches.txt | 1 + ...dimensions_to_journal_template_accounts.py | 11 +++++ 8 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 erpnext/patches/v16_0/add_accounting_dimensions_to_journal_template_accounts.py diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index c115204c28b..640ad3d9ad2 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -277,7 +277,21 @@ frappe.ui.form.on("Journal Entry", { var update_jv_details = function (doc, r) { $.each(r, function (i, d) { var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts"); - frappe.model.set_value(row.doctype, row.name, "account", d.account); + const { + idx, + name, + owner, + parent, + parenttype, + parentfield, + creation, + modified, + modified_by, + doctype, + docstatus, + ...fields + } = d; + frappe.model.set_value(row.doctype, row.name, fields); }); refresh_field("accounts"); }; diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index cfd6ccfe375..6ef2a80c068 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -3,6 +3,7 @@ frappe.ui.form.on("Journal Entry Template", { onload: function (frm) { + erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); if (frm.is_new()) { frappe.call({ type: "GET", @@ -37,6 +38,31 @@ frappe.ui.form.on("Journal Entry Template", { return { filters: filters }; }); + + frm.set_query("project", "accounts", function (doc, cdt, cdn) { + let row = frappe.get_doc(cdt, cdn); + let filters = { + company: doc.company, + }; + if (row.party_type == "Customer") { + filters.customer = row.party; + } + return { + query: "erpnext.controllers.queries.get_project_name", + filters, + }; + }); + + frm.set_query("party_type", "accounts", function (doc, cdt, cdn) { + const row = locals[cdt][cdn]; + + return { + query: "erpnext.setup.doctype.party_type.party_type.get_party_type", + filters: { + account: row.account, + }, + }; + }); }, voucher_type: function (frm) { var add_accounts = function (doc, r) { diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py index f87efc54e18..f86706774fc 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py @@ -3,6 +3,7 @@ import frappe +from frappe import _ from frappe.model.document import Document @@ -42,7 +43,29 @@ class JournalEntryTemplate(Document): ] # end: auto-generated types - pass + def validate(self): + self.validate_party() + + def validate_party(self): + """ + Loop over all accounts and see if party and party type is set correctly + """ + for account in self.accounts: + if account.party_type: + account_type = frappe.get_cached_value("Account", account.account, "account_type") + if account_type not in ["Receivable", "Payable"]: + frappe.throw( + _( + "Check row {0} for account {1}: Party Type is only allowed for Receivable or Payable accounts" + ).format(account.idx, account.account) + ) + + if account.party and not account.party_type: + frappe.throw( + _("Check row {0} for account {1}: Party is only allowed if Party Type is set").format( + account.idx, account.account + ) + ) @frappe.whitelist() diff --git a/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json index e621fa2557f..0ec8b78884a 100644 --- a/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json +++ b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json @@ -5,7 +5,13 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "account" + "account", + "party_type", + "party", + "accounting_dimensions_section", + "cost_center", + "dimension_col_break", + "project" ], "fields": [ { @@ -15,18 +21,55 @@ "label": "Account", "options": "Account", "reqd": 1 + }, + { + "fieldname": "party_type", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Party Type", + "options": "DocType" + }, + { + "fieldname": "party", + "fieldtype": "Dynamic Link", + "in_list_view": 1, + "label": "Party", + "options": "party_type" + }, + { + "collapsible": 1, + "fieldname": "accounting_dimensions_section", + "fieldtype": "Section Break", + "label": "Accounting Dimensions" + }, + { + "fieldname": "cost_center", + "fieldtype": "Link", + "label": "Cost Center", + "options": "Cost Center" + }, + { + "fieldname": "project", + "fieldtype": "Link", + "label": "Project", + "options": "Project" + }, + { + "fieldname": "dimension_col_break", + "fieldtype": "Column Break" } ], "istable": 1, "links": [], - "modified": "2024-03-27 13:09:58.986448", + "modified": "2026-01-09 13:16:27.615083", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Template Account", "owner": "Administrator", "permissions": [], + "row_format": "Dynamic", "sort_field": "creation", "sort_order": "DESC", "states": [], "track_changes": 1 -} \ No newline at end of file +} diff --git a/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py index 2426f577a1d..1ab32d34606 100644 --- a/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py +++ b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py @@ -16,9 +16,13 @@ class JournalEntryTemplateAccount(Document): from frappe.types import DF account: DF.Link + cost_center: DF.Link | None parent: DF.Data parentfield: DF.Data parenttype: DF.Data + party: DF.DynamicLink | None + party_type: DF.Link | None + project: DF.Link | None # end: auto-generated types pass diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 9440459fef3..bdbe2292139 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -534,6 +534,7 @@ accounting_dimension_doctypes = [ "Purchase Order Item", "Sales Order Item", "Journal Entry Account", + "Journal Entry Template Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 0e5d01b0353..838c837321e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -456,6 +456,7 @@ erpnext.patches.v16_0.update_tax_withholding_field_in_payment_entry erpnext.patches.v16_0.migrate_tax_withholding_data erpnext.patches.v16_0.update_corrected_cancelled_status erpnext.patches.v16_0.fix_barcode_typo +erpnext.patches.v16_0.add_accounting_dimensions_to_journal_template_accounts erpnext.patches.v16_0.set_post_change_gl_entries_on_pos_settings execute:frappe.delete_doc_if_exists("Workspace Sidebar", "Opening & Closing") erpnext.patches.v15_0.create_accounting_dimensions_in_advance_taxes_and_charges diff --git a/erpnext/patches/v16_0/add_accounting_dimensions_to_journal_template_accounts.py b/erpnext/patches/v16_0/add_accounting_dimensions_to_journal_template_accounts.py new file mode 100644 index 00000000000..afdcbaeb706 --- /dev/null +++ b/erpnext/patches/v16_0/add_accounting_dimensions_to_journal_template_accounts.py @@ -0,0 +1,11 @@ +from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( + get_dimensions, + make_dimension_in_accounting_doctypes, +) + + +def execute(): + dimensions_and_defaults = get_dimensions() + if dimensions_and_defaults: + for dimension in dimensions_and_defaults[0]: + make_dimension_in_accounting_doctypes(dimension, ["Journal Entry Template Account"])