fix: COA Importer showing blank validations
(cherry picked from commit 0660d6ed01e0668ce828cf9bae9790aead874233)
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 66a269e..d61f8a6 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 @@
// 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 @@
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 @@
});
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 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 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 bd2a6f1..5e596f8 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 @@
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 @@
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):