mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
Move logic for download template to dialog
This commit is contained in:
@@ -20,30 +20,57 @@ frappe.ui.form.on('Chart of Accounts Importer', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
download_template: function(frm) {
|
download_template: function(frm) {
|
||||||
|
var d = new frappe.ui.Dialog({
|
||||||
|
title: __("Download Template"),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
label : "File Type",
|
||||||
|
fieldname: "file_type",
|
||||||
|
fieldtype: "Select",
|
||||||
|
reqd: 1,
|
||||||
|
options: ["Excel", "CSV"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Template Type",
|
||||||
|
fieldname: "template_type",
|
||||||
|
fieldtype: "Select",
|
||||||
|
reqd: 1,
|
||||||
|
options: ["Sample Template", "Blank Template"],
|
||||||
|
change: () => {
|
||||||
|
let template_type = d.get_value('template_type');
|
||||||
|
|
||||||
if (!frm.doc.template_type) {
|
if (template_type === "Sample Template") {
|
||||||
frappe.throw(__('Please select <b>Template Type</b> to download template'));
|
d.set_df_property('template_type', 'description',
|
||||||
}
|
`The Sample Template contains all the required accounts pre filled in the template.
|
||||||
|
You can add more accounts or change existing accounts in the template as per your choice.`);
|
||||||
|
} else {
|
||||||
|
d.set_df_property('template_type', 'description',
|
||||||
|
`The Blank Template contains just the account type and root type required to build the Chart
|
||||||
|
of Accounts. Please enter the account names and add more rows as per your requirement.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
primary_action: function() {
|
||||||
|
var data = d.get_values();
|
||||||
|
|
||||||
open_url_post(
|
if (!data.template_type) {
|
||||||
'/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template',
|
frappe.throw(__('Please select <b>Template Type</b> to download template'));
|
||||||
{
|
}
|
||||||
file_type: frm.doc.file_type,
|
|
||||||
template_type: frm.doc.template_type
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
template_type: function(frm) {
|
open_url_post(
|
||||||
if (frm.doc.template_type == 'Sample Template') {
|
'/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template',
|
||||||
frm.set_df_property('template_type', 'description',
|
{
|
||||||
`The Sample Template contains all the required accounts pre filled in the template.
|
file_type: data.file_type,
|
||||||
You can add more accounts or change existing accounts in the template as per your choice.`);
|
template_type: data.template_type
|
||||||
} else {
|
}
|
||||||
frm.set_df_property('template_type', 'description',
|
);
|
||||||
`The Blank Template contains just the account type and root type required to build the Chart
|
|
||||||
of Accounts. Please enter the account names and add more rows as per your requirement.`);
|
d.hide();
|
||||||
}
|
},
|
||||||
|
primary_action_label: __('Download')
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
},
|
},
|
||||||
|
|
||||||
import_file: function (frm) {
|
import_file: function (frm) {
|
||||||
@@ -96,7 +123,7 @@ var validate_csv_data = function(frm) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var create_import_button = function(frm) {
|
var create_import_button = function(frm) {
|
||||||
frm.page.set_primary_action(__("Start Import"), function () {
|
frm.page.set_primary_action(__("Import"), function () {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa",
|
method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa",
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -9,10 +9,7 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"company",
|
"company",
|
||||||
"file_type",
|
|
||||||
"template_type",
|
|
||||||
"download_template",
|
"download_template",
|
||||||
"import_file_section",
|
|
||||||
"import_file",
|
"import_file",
|
||||||
"chart_preview",
|
"chart_preview",
|
||||||
"chart_tree"
|
"chart_tree"
|
||||||
@@ -26,11 +23,7 @@
|
|||||||
"options": "Company"
|
"options": "Company"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "import_file_section",
|
"depends_on": "company",
|
||||||
"fieldtype": "Section Break"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"depends_on": "eval:!doc.__islocal",
|
|
||||||
"fieldname": "import_file",
|
"fieldname": "import_file",
|
||||||
"fieldtype": "Attach",
|
"fieldtype": "Attach",
|
||||||
"label": "Attach custom Chart of Accounts file"
|
"label": "Attach custom Chart of Accounts file"
|
||||||
@@ -51,28 +44,13 @@
|
|||||||
"fieldname": "download_template",
|
"fieldname": "download_template",
|
||||||
"fieldtype": "Button",
|
"fieldtype": "Button",
|
||||||
"label": "Download Template"
|
"label": "Download Template"
|
||||||
},
|
|
||||||
{
|
|
||||||
"depends_on": "company",
|
|
||||||
"fieldname": "file_type",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"label": "File Type",
|
|
||||||
"options": "CSV\nExcel"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"depends_on": "company",
|
|
||||||
"fieldname": "template_type",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"label": "Template Type",
|
|
||||||
"options": "\nBlank Template\nSample Template",
|
|
||||||
"reqd": 1
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_toolbar": 1,
|
"hide_toolbar": 1,
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-02-24 19:07:52.670868",
|
"modified": "2020-02-28 08:49:11.422846",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Chart of Accounts Importer",
|
"name": "Chart of Accounts Importer",
|
||||||
@@ -88,5 +66,6 @@
|
|||||||
],
|
],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC"
|
"sort_order": "DESC"
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,9 @@ def validate_company(company):
|
|||||||
'allow_account_creation_against_child_company'])
|
'allow_account_creation_against_child_company'])
|
||||||
|
|
||||||
if parent_company and (not allow_account_creation_against_child_company):
|
if parent_company and (not allow_account_creation_against_child_company):
|
||||||
frappe.throw(_("""{0} is child company. Please import accounts in parent company
|
frappe.throw(_("""{0} is a child company. Please import accounts against parent company
|
||||||
or enable {1} in company master""").format(frappe.bold(company),
|
or enable {1} in company master""").format(frappe.bold(company),
|
||||||
frappe.bold('Allow Account Creation Against Child Company')))
|
frappe.bold('Allow Account Creation Against Child Company')), title='Wrong Company')
|
||||||
|
|
||||||
if frappe.db.get_all('GL Entry', {"company": company}, "name", limit=1):
|
if frappe.db.get_all('GL Entry', {"company": company}, "name", limit=1):
|
||||||
return False
|
return False
|
||||||
@@ -102,7 +102,7 @@ def generate_data_from_excel(file_doc, extension, as_dict=False):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_coa(doctype, parent, file_type, is_root=False, file_name=None):
|
def get_coa(doctype, parent, is_root=False, file_name=None):
|
||||||
''' called by tree view (to fetch node's children) '''
|
''' called by tree view (to fetch node's children) '''
|
||||||
|
|
||||||
file_doc, extension = get_file(file_name)
|
file_doc, extension = get_file(file_name)
|
||||||
@@ -144,15 +144,18 @@ def build_forest(data):
|
|||||||
|
|
||||||
# returns the path of any node in list format
|
# returns the path of any node in list format
|
||||||
def return_parent(data, child):
|
def return_parent(data, child):
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
account_name, parent_account = row[0:2]
|
account_name, parent_account = row[0:2]
|
||||||
if parent_account == account_name == child:
|
if parent_account == account_name == child:
|
||||||
return [parent_account]
|
return [parent_account]
|
||||||
elif account_name == child:
|
elif account_name == child:
|
||||||
parent_account_list = return_parent(data, parent_account)
|
parent_account_list = return_parent(data, parent_account)
|
||||||
if not parent_account_list and parent_account:
|
if not parent_account_list:
|
||||||
frappe.throw(_("The parent account {0} does not exists")
|
frappe.throw(_("The parent account {0} does not exists in the uploaded template").format(
|
||||||
.format(parent_account))
|
frappe.bold(parent_account)))
|
||||||
|
|
||||||
return [child] + parent_account_list
|
return [child] + parent_account_list
|
||||||
|
|
||||||
charts_map, paths = {}, []
|
charts_map, paths = {}, []
|
||||||
@@ -228,7 +231,7 @@ def get_template(template_type):
|
|||||||
writer.writerow(['', '', '', 1, '', root_type])
|
writer.writerow(['', '', '', 1, '', root_type])
|
||||||
|
|
||||||
for account in get_mandatory_group_accounts():
|
for account in get_mandatory_group_accounts():
|
||||||
writer.writerow(['', '', '', 1, account, 'Asset'])
|
writer.writerow(['', '', '', 1, account, "Asset"])
|
||||||
|
|
||||||
for account_type in get_mandatory_account_types():
|
for account_type in get_mandatory_account_types():
|
||||||
writer.writerow(['', '', '', 0, account_type.get('account_type'), account_type.get('root_type')])
|
writer.writerow(['', '', '', 0, account_type.get('account_type'), account_type.get('root_type')])
|
||||||
@@ -239,24 +242,23 @@ def get_template(template_type):
|
|||||||
|
|
||||||
def get_sample_template(writer):
|
def get_sample_template(writer):
|
||||||
template = [
|
template = [
|
||||||
['Account Name', 'Parent Account', 'Account Number', 'Is Group', 'Account Type', 'Root Type'],
|
["Application Of Funds(Assets)", "", "", 1, "", "Asset"],
|
||||||
['Application Of Funds(Assets)', '', '', 1, '', 'Asset'],
|
["Sources Of Funds(Liabilities)", "", "", 1, "", "Liability"],
|
||||||
['Sources Of Funds(Liabilities)', '', '', 1, '', 'Liability'],
|
["Equity", "", "", 1, "", "Equity"],
|
||||||
['Equity', '', '', 1, '', 'Equity'],
|
["Expenses", "", "", 1, "", "Expense"],
|
||||||
['Expenses', '', '', 1, '', 'Expense'],
|
["Income", "", "", 1, "", "Income"],
|
||||||
['Income', '', '', 1, '', 'Income'],
|
["Bank Accounts", "Application Of Funds(Assets)", "", 1, "Bank", "Asset"],
|
||||||
['Bank Accounts', 'Application Of Funds(Assets)', '', 1, 'Bank', 'Asset'],
|
["Cash In Hand", "Application Of Funds(Assets)", "", 1, "Cash", "Asset"],
|
||||||
['Cash In Hand', 'Application Of Funds(Assets)', '', 1, 'Cash', 'Asset'],
|
["Stock Assets", "Application Of Funds(Assets)", "", 1, "Stock", "Asset"],
|
||||||
['Stock Assets', 'Application Of Funds(Assets)', '', 1, 'Stock', 'Asset'],
|
["Cost Of Goods Sold", "Expenses", "", 0, "Cost of Goods Sold", "Expense"],
|
||||||
['Cost Of Goods Sold', 'Expenses', '', 0, 'Cost of Goods Sold', 'Expense'],
|
["Asset Depreciation", "Expenses", "", 0, "Depreciation", "Expense"],
|
||||||
['Asset Depreciation', 'Expenses', '', 0, 'Depreciation', 'Expense'],
|
["Fixed Assets", "Application Of Funds(Assets)", "", 0, "Fixed Asset", "Asset"],
|
||||||
['Fixed Assets', 'Application Of Funds(Assets)', '', 0, 'Fixed Asset', 'Asset'],
|
["Accounts Payable", "Sources Of Funds(Liabilities)", "", 0, "Payable", "Liability"],
|
||||||
['Accounts Payable', 'Sources Of Funds(Liabilities)', '', 0, 'Payable', 'Liability'],
|
["Accounts Receivable", "Application Of Funds(Assets)", "", 1, "Receivable", "Asset"],
|
||||||
['Accounts Receivable', 'Application Of Funds(Assets)', '', 1, 'Receivable', 'Asset'],
|
["Stock Expenses", "Expenses", "", 0, "Stock Adjustment", "Expense"],
|
||||||
['Stock Expenses', 'Expenses', '', 0, 'Stock Adjustment', 'Expense'],
|
["Sample Bank", "Bank Accounts", "", 0, "Bank", "Asset"],
|
||||||
['Sample Bank', 'Bank Accounts', '', 0, 'Bank', 'Asset'],
|
["Cash", "Cash In Hand", "", 0, "Cash", "Asset"],
|
||||||
['Cash', 'Cash In Hand', '', 0, 'Cash', 'Asset'],
|
["Stores", "Stock Assets", "", 0, "Stock", "Asset"],
|
||||||
['Stores', 'Stock Asset', '', 0, 'Stock', 'Asset'],
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for row in template:
|
for row in template:
|
||||||
|
|||||||
Reference in New Issue
Block a user