From 2fb6bc986781d7819afd860cb046a6f060baaaf0 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Thu, 15 Aug 2019 17:06:32 +0530 Subject: [PATCH 1/3] fix: Default dimensions in child doctypes --- .../accounting_dimension.js | 7 ---- .../accounting_dimension_detail.json | 8 ++--- .../public/js/utils/dimension_tree_filter.js | 36 ++++++++++++++----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js index 88b11dd678..5cea0d15bf 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js @@ -40,16 +40,9 @@ frappe.ui.form.on('Accounting Dimension', { }, document_type: function(frm) { - frm.set_value('label', frm.doc.document_type); frm.set_value('fieldname', frappe.model.scrub(frm.doc.document_type)); - if (frm.is_new()){ - let row = frappe.model.add_child(frm.doc, "Accounting Dimension Detail", "dimension_defaults"); - row.reference_document = frm.doc.document_type; - frm.refresh_fields("dimension_defaults"); - } - frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => { if (r && r.document_type) { frm.set_df_property('document_type', 'description', "Document type is already set as dimension"); diff --git a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json index 1ccef6cc7a..e9e1f43f99 100644 --- a/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json +++ b/erpnext/accounts/doctype/accounting_dimension_detail/accounting_dimension_detail.json @@ -17,8 +17,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Company", - "options": "Company", - "reqd": 1 + "options": "Company" }, { "fieldname": "reference_document", @@ -34,8 +33,7 @@ "fieldtype": "Dynamic Link", "in_list_view": 1, "label": "Default Dimension", - "options": "reference_document", - "reqd": 1 + "options": "reference_document" }, { "columns": 3, @@ -55,7 +53,7 @@ } ], "istable": 1, - "modified": "2019-07-17 23:34:33.026883", + "modified": "2019-08-15 11:59:09.389891", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Dimension Detail", diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index f1c92091a8..72a05b4221 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -1,12 +1,13 @@ frappe.provide('frappe.ui.form'); erpnext.doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", - "Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Sales Invoice Item", "Purchase Invoice Item", - "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item", - "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule", - "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", - "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription", - "Subscription Plan"]; + "Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Shipping Rule", "Loyalty Program", + "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", + "Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Landed Cost Item", "Asset"] + +erpnext.child_docs = ["Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", + "Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", + "Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan"] frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters", @@ -26,8 +27,19 @@ erpnext.doctypes_with_dimensions.forEach((doctype) => { "is_group": 0 }); } - if (frm.is_new() && frappe.meta.has_field(doctype, 'company') && frm.doc.company) { - frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + + if (frappe.meta.has_field(doctype, dimension['fieldname'])) { + if (frm.is_new() && frappe.meta.has_field(doctype, 'company') && frm.doc.company) { + frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + } + } + + if (frm.doc.items && frm.doc.items.length) { + frm.doc.items[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; + } + + if (frm.doc.accounts && frm.doc.accounts.length) { + frm.doc.accounts[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; } }); }); @@ -36,11 +48,17 @@ erpnext.doctypes_with_dimensions.forEach((doctype) => { company: function(frm) { if(frm.doc.company) { erpnext.dimension_filters.forEach((dimension) => { - frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + if (frappe.meta.has_field(doctype, dimension['fieldname'])) { + frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + } }); } }, + }); +}); +erpnext.child_docs.forEach((doctype) => { + frappe.ui.form.on(doctype, { items_add: function(frm, cdt, cdn) { erpnext.dimension_filters.forEach((dimension) => { var row = frappe.get_doc(cdt, cdn); From 8d0b6f9a60c606423e3fea258ccfe1b12127560d Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Fri, 16 Aug 2019 14:00:26 +0530 Subject: [PATCH 2/3] fix: Handling if no default dimension exists --- .../public/js/utils/dimension_tree_filter.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index 72a05b4221..aada92d7da 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -28,25 +28,27 @@ erpnext.doctypes_with_dimensions.forEach((doctype) => { }); } - if (frappe.meta.has_field(doctype, dimension['fieldname'])) { - if (frm.is_new() && frappe.meta.has_field(doctype, 'company') && frm.doc.company) { - frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + if (Object.keys(erpnext.default_dimensions).length > 0) { + if (frappe.meta.has_field(doctype, dimension['fieldname'])) { + if (frm.is_new() && frappe.meta.has_field(doctype, 'company') && frm.doc.company) { + frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); + } } - } - if (frm.doc.items && frm.doc.items.length) { - frm.doc.items[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; - } + if (frm.doc.items && frm.doc.items.length) { + frm.doc.items[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; + } - if (frm.doc.accounts && frm.doc.accounts.length) { - frm.doc.accounts[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; + if (frm.doc.accounts && frm.doc.accounts.length) { + frm.doc.accounts[0][dimension['fieldname']] = erpnext.default_dimensions[frm.doc.company][dimension['document_type']]; + } } }); }); }, company: function(frm) { - if(frm.doc.company) { + if(frm.doc.company && (Object.keys(erpnext.default_dimensions).length > 0)) { erpnext.dimension_filters.forEach((dimension) => { if (frappe.meta.has_field(doctype, dimension['fieldname'])) { frm.set_value(dimension['fieldname'], erpnext.default_dimensions[frm.doc.company][dimension['document_type']]); From 0a2ed6da37848cd10315366fcc063545c2504d6b Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Fri, 16 Aug 2019 15:50:17 +0530 Subject: [PATCH 3/3] fix: Add missing semicolon --- erpnext/public/js/utils/dimension_tree_filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index aada92d7da..e6c18a149b 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -3,11 +3,11 @@ frappe.provide('frappe.ui.form'); erpnext.doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset", "Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Shipping Rule", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", - "Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Landed Cost Item", "Asset"] + "Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Landed Cost Item", "Asset"]; erpnext.child_docs = ["Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", - "Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan"] + "Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan"]; frappe.call({ method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters",