From 020f94532bf8e1893fcf4c7e6bb78b9088d8deac Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 5 Oct 2021 12:20:14 +0530 Subject: [PATCH 1/2] fix: COA Importer showing blank validations (cherry picked from commit 0660d6ed01e0668ce828cf9bae9790aead874233) --- .../chart_of_accounts_importer.js | 91 +++++++++---------- .../chart_of_accounts_importer.py | 7 +- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js index 66a269e7a7..d61f8a6c01 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js @@ -10,6 +10,15 @@ frappe.ui.form.on('Chart of Accounts Importer', { // make company mandatory frm.set_df_property('company', 'reqd', frm.doc.company ? 0 : 1); frm.set_df_property('import_file_section', 'hidden', frm.doc.company ? 0 : 1); + + if (frm.doc.import_file) { + frappe.run_serially([ + () => generate_tree_preview(frm), + () => create_import_button(frm), + () => frm.set_df_property('chart_preview', 'hidden', 0) + ]); + } + frm.set_df_property('chart_preview', 'hidden', $(frm.fields_dict['chart_tree'].wrapper).html()!="" ? 0 : 1); }, @@ -72,13 +81,6 @@ frappe.ui.form.on('Chart of Accounts Importer', { if (!frm.doc.import_file) { frm.page.set_indicator(""); $(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper on removing file - } else { - frappe.run_serially([ - () => validate_coa(frm), - () => generate_tree_preview(frm), - () => create_import_button(frm), - () => frm.set_df_property('chart_preview', 'hidden', 0), - ]); } }, @@ -104,26 +106,24 @@ frappe.ui.form.on('Chart of Accounts Importer', { }); var create_import_button = function(frm) { - if (frm.page.show_import_button) { - frm.page.set_primary_action(__("Import"), function () { - return frappe.call({ - method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa", - args: { - file_name: frm.doc.import_file, - company: frm.doc.company - }, - freeze: true, - freeze_message: __("Creating Accounts..."), - callback: function(r) { - if (!r.exc) { - clearInterval(frm.page["interval"]); - frm.page.set_indicator(__('Import Successful'), 'blue'); - create_reset_button(frm); - } + frm.page.set_primary_action(__("Import"), function () { + return frappe.call({ + method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa", + args: { + file_name: frm.doc.import_file, + company: frm.doc.company + }, + freeze: true, + freeze_message: __("Creating Accounts..."), + callback: function(r) { + if (!r.exc) { + clearInterval(frm.page["interval"]); + frm.page.set_indicator(__('Import Successful'), 'blue'); + create_reset_button(frm); } - }); - }).addClass('btn btn-primary'); - } + } + }); + }).addClass('btn btn-primary'); }; var create_reset_button = function(frm) { @@ -137,7 +137,6 @@ var create_reset_button = function(frm) { var validate_coa = function(frm) { if (frm.doc.import_file) { let parent = __('All Accounts'); - return frappe.call({ 'method': 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa', 'args': { @@ -157,25 +156,23 @@ var validate_coa = function(frm) { }; var generate_tree_preview = function(frm) { - if (frm.doc.import_file) { - let parent = __('All Accounts'); - $(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data + let parent = __('All Accounts'); + $(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data - // generate tree structure based on the csv data - return new frappe.ui.Tree({ - parent: $(frm.fields_dict['chart_tree'].wrapper), - label: parent, - expandable: true, - method: 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa', - args: { - file_name: frm.doc.import_file, - parent: parent, - doctype: 'Chart of Accounts Importer', - file_type: frm.doc.file_type - }, - onclick: function(node) { - parent = node.value; - } - }); - } + // generate tree structure based on the csv data + return new frappe.ui.Tree({ + parent: $(frm.fields_dict['chart_tree'].wrapper), + label: parent, + expandable: true, + method: 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa', + args: { + file_name: frm.doc.import_file, + parent: parent, + doctype: 'Chart of Accounts Importer', + file_type: frm.doc.file_type + }, + onclick: function(node) { + parent = node.value; + } + }); }; diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py index bd2a6f1b08..5e596f8677 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py @@ -25,7 +25,9 @@ from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import class ChartofAccountsImporter(Document): - pass + def validate(self): + if self.import_file: + get_coa('Chart of Accounts Importer', 'All Accounts', file_name=self.import_file, for_validate=1) def validate_columns(data): if not data: @@ -34,7 +36,8 @@ def validate_columns(data): no_of_columns = max([len(d) for d in data]) if no_of_columns > 7: - frappe.throw(_('More columns found than expected. Please compare the uploaded file with standard template')) + frappe.throw(_('More columns found than expected. Please compare the uploaded file with standard template'), + title=(_("Wrong Template"))) @frappe.whitelist() def validate_company(company): From a2b5e678fec3c7157fe3a280ff3e0dbcc15123ec Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 5 Oct 2021 14:51:35 +0530 Subject: [PATCH 2/2] fix: Use get_list instead of get_all to avoid perm issues (cherry picked from commit 9507b2d752a40c0dd9e8b43ae3ef64435457c85e) --- erpnext/setup/setup_wizard/operations/taxes_setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py index faa25dfbaa..58a14d20f2 100644 --- a/erpnext/setup/setup_wizard/operations/taxes_setup.py +++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py @@ -192,7 +192,7 @@ def get_or_create_account(company_name, account): default_root_type = 'Liability' root_type = account.get('root_type', default_root_type) - existing_accounts = frappe.get_list('Account', + existing_accounts = frappe.get_all('Account', filters={ 'company': company_name, 'root_type': root_type @@ -247,7 +247,7 @@ def get_or_create_tax_group(company_name, root_type): # Create a new group account named 'Duties and Taxes' or 'Tax Assets' just # below the root account - root_account = frappe.get_list('Account', { + root_account = frappe.get_all('Account', { 'is_group': 1, 'root_type': root_type, 'company': company_name,