Merge pull request #21478 from deepeshgarg007/duplicate_code_v13

fix: Remove duplicate code from accounting dimension
This commit is contained in:
Deepesh Garg 2020-04-28 20:36:50 +05:30 committed by GitHub
commit e317b79361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ doctypes_with_dimensions.forEach((doctype) => {
onload: function(frm) { onload: function(frm) {
erpnext.dimension_filters.forEach((dimension) => { erpnext.dimension_filters.forEach((dimension) => {
frappe.model.with_doctype(dimension['document_type'], () => { frappe.model.with_doctype(dimension['document_type'], () => {
if (frappe.meta.has_field(dimension['document_type'], 'is_group')) { if(frappe.meta.has_field(dimension['document_type'], 'is_group')) {
frm.set_query(dimension['fieldname'], { frm.set_query(dimension['fieldname'], {
"is_group": 0 "is_group": 0
}); });
@ -42,19 +42,21 @@ doctypes_with_dimensions.forEach((doctype) => {
update_dimension: function(frm) { update_dimension: function(frm) {
erpnext.dimension_filters.forEach((dimension) => { erpnext.dimension_filters.forEach((dimension) => {
if (frm.is_new()) { if(frm.is_new()) {
if (frm.doc.company && Object.keys(default_dimensions || {}).length > 0 if(frm.doc.company && Object.keys(default_dimensions || {}).length > 0
&& default_dimensions[frm.doc.company]) { && default_dimensions[frm.doc.company]) {
if (frappe.meta.has_field(doctype, dimension['fieldname'])) { let default_dimension = default_dimensions[frm.doc.company][dimension['document_type']];
frm.set_value(dimension['fieldname'],
default_dimensions[frm.doc.company][dimension['document_type']]);
}
$.each(frm.doc.items || frm.doc.accounts || [], function(i, row) { if(default_dimension) {
frappe.model.set_value(row.doctype, row.name, dimension['fieldname'], if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
default_dimensions[frm.doc.company][dimension['document_type']]) frm.set_value(dimension['fieldname'], default_dimension);
}); }
$.each(frm.doc.items || frm.doc.accounts || [], function(i, row) {
frappe.model.set_value(row.doctype, row.name, dimension['fieldname'], default_dimension);
});
}
} }
} }
}); });
@ -71,20 +73,6 @@ child_docs.forEach((doctype) => {
}); });
}, },
accounts_add: function(frm, cdt, cdn) {
erpnext.dimension_filters.forEach((dimension) => {
var row = frappe.get_doc(cdt, cdn);
frm.script_manager.copy_from_first_row("accounts", row, [dimension['fieldname']]);
});
},
items_add: function(frm, cdt, cdn) {
erpnext.dimension_filters.forEach((dimension) => {
var row = frappe.get_doc(cdt, cdn);
frm.script_manager.copy_from_first_row("items", row, [dimension['fieldname']]);
});
},
accounts_add: function(frm, cdt, cdn) { accounts_add: function(frm, cdt, cdn) {
erpnext.dimension_filters.forEach((dimension) => { erpnext.dimension_filters.forEach((dimension) => {
var row = frappe.get_doc(cdt, cdn); var row = frappe.get_doc(cdt, cdn);