mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 07:20:26 +00:00
fix: Improvements in COA Importer (#27584)
(cherry picked from commit f07ff92a35)
# Conflicts:
# erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.js
# erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py
This commit is contained in:
@@ -81,6 +81,11 @@ 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
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
} else {
|
||||
generate_tree_preview(frm);
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
}
|
||||
},
|
||||
|
||||
@@ -156,9 +161,11 @@ var validate_coa = function(frm) {
|
||||
};
|
||||
|
||||
var generate_tree_preview = function(frm) {
|
||||
let parent = __('All Accounts');
|
||||
$(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data
|
||||
if (frm.doc.import_file) {
|
||||
let parent = __('All Accounts');
|
||||
$(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data
|
||||
|
||||
<<<<<<< HEAD
|
||||
// generate tree structure based on the csv data
|
||||
return new frappe.ui.Tree({
|
||||
parent: $(frm.fields_dict['chart_tree'].wrapper),
|
||||
@@ -175,4 +182,23 @@ var generate_tree_preview = function(frm) {
|
||||
parent = node.value;
|
||||
}
|
||||
});
|
||||
=======
|
||||
// generate tree structure based on the csv data
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import
|
||||
|
||||
|
||||
class ChartofAccountsImporter(Document):
|
||||
<<<<<<< HEAD
|
||||
def validate(self):
|
||||
if self.import_file:
|
||||
get_coa(
|
||||
@@ -33,15 +34,26 @@ class ChartofAccountsImporter(Document):
|
||||
def validate_columns(data):
|
||||
if not data:
|
||||
frappe.throw(_("No data found. Seems like you uploaded a blank file"))
|
||||
=======
|
||||
pass
|
||||
|
||||
def validate_columns(data):
|
||||
if not data:
|
||||
frappe.throw(_('No data found. Seems like you uploaded a blank file'))
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
|
||||
no_of_columns = max([len(d) for d in data])
|
||||
|
||||
if no_of_columns > 7:
|
||||
<<<<<<< HEAD
|
||||
frappe.throw(
|
||||
_("More columns found than expected. Please compare the uploaded file with standard template"),
|
||||
title=(_("Wrong Template")),
|
||||
)
|
||||
|
||||
=======
|
||||
frappe.throw(_('More columns found than expected. Please compare the uploaded file with standard template'))
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
|
||||
@frappe.whitelist()
|
||||
def validate_company(company):
|
||||
@@ -158,7 +170,13 @@ def get_coa(doctype, parent, is_root=False, file_name=None, for_validate=0):
|
||||
data = generate_data_from_excel(file_doc, extension)
|
||||
|
||||
validate_columns(data)
|
||||
<<<<<<< HEAD
|
||||
validate_accounts(file_doc, extension)
|
||||
=======
|
||||
validate_accounts(data)
|
||||
forest = build_forest(data)
|
||||
accounts = build_tree_from_json("", chart_data=forest) # returns alist of dict in a tree render-able form
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
|
||||
if not for_validate:
|
||||
forest = build_forest(data)
|
||||
@@ -387,9 +405,14 @@ def validate_accounts(file_doc, extension):
|
||||
|
||||
return [True, len(accounts)]
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
def validate_root(accounts):
|
||||
roots = [accounts[d] for d in accounts if not accounts[d].get("parent_account")]
|
||||
=======
|
||||
def validate_root(accounts):
|
||||
roots = [accounts[d] for d in accounts if not accounts[d].get('parent_account')]
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
error_messages = []
|
||||
|
||||
for account in roots:
|
||||
@@ -448,6 +471,17 @@ def get_mandatory_account_types():
|
||||
]
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
def validate_account_types(accounts):
|
||||
account_types_for_ledger = ["Cost of Goods Sold", "Depreciation", "Fixed Asset", "Payable", "Receivable", "Stock Adjustment"]
|
||||
account_types = [accounts[d]["account_type"] for d in accounts if not cint(accounts[d]['is_group']) == 1]
|
||||
|
||||
missing = list(set(account_types_for_ledger) - set(account_types))
|
||||
if missing:
|
||||
frappe.throw(_("Please identify/create Account (Ledger) for type - {0}").format(' , '.join(missing)))
|
||||
|
||||
>>>>>>> f07ff92a35 (fix: Improvements in COA Importer (#27584))
|
||||
def unset_existing_data(company):
|
||||
linked = frappe.db.sql(
|
||||
'''select fieldname from tabDocField
|
||||
|
||||
Reference in New Issue
Block a user