mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 09:43:49 +00:00
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 ef44528ba5)
This commit is contained in:
@@ -277,7 +277,21 @@ frappe.ui.form.on("Journal Entry", {
|
|||||||
var update_jv_details = function (doc, r) {
|
var update_jv_details = function (doc, r) {
|
||||||
$.each(r, function (i, d) {
|
$.each(r, function (i, d) {
|
||||||
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
|
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");
|
refresh_field("accounts");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
frappe.ui.form.on("Journal Entry Template", {
|
frappe.ui.form.on("Journal Entry Template", {
|
||||||
onload: function (frm) {
|
onload: function (frm) {
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
if (frm.is_new()) {
|
if (frm.is_new()) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -37,6 +38,31 @@ frappe.ui.form.on("Journal Entry Template", {
|
|||||||
|
|
||||||
return { filters: filters };
|
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) {
|
voucher_type: function (frm) {
|
||||||
var add_accounts = function (doc, r) {
|
var add_accounts = function (doc, r) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +43,29 @@ class JournalEntryTemplate(Document):
|
|||||||
]
|
]
|
||||||
# end: auto-generated types
|
# 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()
|
@frappe.whitelist()
|
||||||
|
|||||||
@@ -5,7 +5,13 @@
|
|||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"account"
|
"account",
|
||||||
|
"party_type",
|
||||||
|
"party",
|
||||||
|
"accounting_dimensions_section",
|
||||||
|
"cost_center",
|
||||||
|
"dimension_col_break",
|
||||||
|
"project"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -15,18 +21,55 @@
|
|||||||
"label": "Account",
|
"label": "Account",
|
||||||
"options": "Account",
|
"options": "Account",
|
||||||
"reqd": 1
|
"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,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-03-27 13:09:58.986448",
|
"modified": "2026-01-09 13:16:27.615083",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Journal Entry Template Account",
|
"name": "Journal Entry Template Account",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
|
"row_format": "Dynamic",
|
||||||
"sort_field": "creation",
|
"sort_field": "creation",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,13 @@ class JournalEntryTemplateAccount(Document):
|
|||||||
from frappe.types import DF
|
from frappe.types import DF
|
||||||
|
|
||||||
account: DF.Link
|
account: DF.Link
|
||||||
|
cost_center: DF.Link | None
|
||||||
parent: DF.Data
|
parent: DF.Data
|
||||||
parentfield: DF.Data
|
parentfield: DF.Data
|
||||||
parenttype: DF.Data
|
parenttype: DF.Data
|
||||||
|
party: DF.DynamicLink | None
|
||||||
|
party_type: DF.Link | None
|
||||||
|
project: DF.Link | None
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -534,6 +534,7 @@ accounting_dimension_doctypes = [
|
|||||||
"Purchase Order Item",
|
"Purchase Order Item",
|
||||||
"Sales Order Item",
|
"Sales Order Item",
|
||||||
"Journal Entry Account",
|
"Journal Entry Account",
|
||||||
|
"Journal Entry Template Account",
|
||||||
"Material Request Item",
|
"Material Request Item",
|
||||||
"Delivery Note Item",
|
"Delivery Note Item",
|
||||||
"Purchase Receipt Item",
|
"Purchase Receipt Item",
|
||||||
|
|||||||
@@ -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.migrate_tax_withholding_data
|
||||||
erpnext.patches.v16_0.update_corrected_cancelled_status
|
erpnext.patches.v16_0.update_corrected_cancelled_status
|
||||||
erpnext.patches.v16_0.fix_barcode_typo
|
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
|
erpnext.patches.v16_0.set_post_change_gl_entries_on_pos_settings
|
||||||
execute:frappe.delete_doc_if_exists("Workspace Sidebar", "Opening & Closing")
|
execute:frappe.delete_doc_if_exists("Workspace Sidebar", "Opening & Closing")
|
||||||
erpnext.patches.v15_0.create_accounting_dimensions_in_advance_taxes_and_charges
|
erpnext.patches.v15_0.create_accounting_dimensions_in_advance_taxes_and_charges
|
||||||
|
|||||||
@@ -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"])
|
||||||
Reference in New Issue
Block a user