fix: COA Importer app related issues (#37238)
fix: COA Importer app related issues (#37238) * fix: COA Importer app related issues * fix: Clear all account links fields befor import * fix: Attribute error (cherry picked from commit 8634abc0210fdb259c8b0e7ffc93976ea0099057) Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
parent
02e225845e
commit
d5bf7a039d
@ -53,10 +53,18 @@ frappe.ui.form.on('Chart of Accounts Importer', {
|
|||||||
of Accounts. Please enter the account names and add more rows as per your requirement.`);
|
of Accounts. Please enter the account names and add more rows as per your requirement.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
label : "Company",
|
||||||
|
fieldname: "company",
|
||||||
|
fieldtype: "Link",
|
||||||
|
reqd: 1,
|
||||||
|
hidden: 1,
|
||||||
|
default: frm.doc.company,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
primary_action: function() {
|
primary_action: function() {
|
||||||
var data = d.get_values();
|
let data = d.get_values();
|
||||||
|
|
||||||
if (!data.template_type) {
|
if (!data.template_type) {
|
||||||
frappe.throw(__('Please select <b>Template Type</b> to download template'));
|
frappe.throw(__('Please select <b>Template Type</b> to download template'));
|
||||||
@ -66,7 +74,8 @@ frappe.ui.form.on('Chart of Accounts Importer', {
|
|||||||
'/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template',
|
'/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template',
|
||||||
{
|
{
|
||||||
file_type: data.file_type,
|
file_type: data.file_type,
|
||||||
template_type: data.template_type
|
template_type: data.template_type,
|
||||||
|
company: data.company
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ from functools import reduce
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.desk.form.linked_with import get_linked_fields
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cint, cstr
|
from frappe.utils import cint, cstr
|
||||||
from frappe.utils.csvutils import UnicodeWriter
|
from frappe.utils.csvutils import UnicodeWriter
|
||||||
@ -294,10 +295,8 @@ def build_response_as_excel(writer):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def download_template(file_type, template_type):
|
def download_template(file_type, template_type, company):
|
||||||
data = frappe._dict(frappe.local.form_dict)
|
writer = get_template(template_type, company)
|
||||||
|
|
||||||
writer = get_template(template_type)
|
|
||||||
|
|
||||||
if file_type == "CSV":
|
if file_type == "CSV":
|
||||||
# download csv file
|
# download csv file
|
||||||
@ -308,8 +307,7 @@ def download_template(file_type, template_type):
|
|||||||
build_response_as_excel(writer)
|
build_response_as_excel(writer)
|
||||||
|
|
||||||
|
|
||||||
def get_template(template_type):
|
def get_template(template_type, company):
|
||||||
|
|
||||||
fields = [
|
fields = [
|
||||||
"Account Name",
|
"Account Name",
|
||||||
"Parent Account",
|
"Parent Account",
|
||||||
@ -335,33 +333,16 @@ def get_template(template_type):
|
|||||||
["", "", "", "", 0, account_type.get("account_type"), account_type.get("root_type")]
|
["", "", "", "", 0, account_type.get("account_type"), account_type.get("root_type")]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
writer = get_sample_template(writer)
|
writer = get_sample_template(writer, company)
|
||||||
|
|
||||||
return writer
|
return writer
|
||||||
|
|
||||||
|
|
||||||
def get_sample_template(writer):
|
def get_sample_template(writer, company):
|
||||||
template = [
|
currency = frappe.db.get_value("Company", company, "default_currency")
|
||||||
["Application Of Funds(Assets)", "", "", "", 1, "", "Asset"],
|
with open(os.path.join(os.path.dirname(__file__), "coa_sample_template.csv"), "r") as f:
|
||||||
["Sources Of Funds(Liabilities)", "", "", "", 1, "", "Liability"],
|
for row in f:
|
||||||
["Equity", "", "", "", 1, "", "Equity"],
|
row = row.strip().split(",") + [currency]
|
||||||
["Expenses", "", "", "", 1, "", "Expense"],
|
|
||||||
["Income", "", "", "", 1, "", "Income"],
|
|
||||||
["Bank Accounts", "Application Of Funds(Assets)", "", "", 1, "Bank", "Asset"],
|
|
||||||
["Cash In Hand", "Application Of Funds(Assets)", "", "", 1, "Cash", "Asset"],
|
|
||||||
["Stock Assets", "Application Of Funds(Assets)", "", "", 1, "Stock", "Asset"],
|
|
||||||
["Cost Of Goods Sold", "Expenses", "", "", 0, "Cost of Goods Sold", "Expense"],
|
|
||||||
["Asset Depreciation", "Expenses", "", "", 0, "Depreciation", "Expense"],
|
|
||||||
["Fixed Assets", "Application Of Funds(Assets)", "", "", 0, "Fixed Asset", "Asset"],
|
|
||||||
["Accounts Payable", "Sources Of Funds(Liabilities)", "", "", 0, "Payable", "Liability"],
|
|
||||||
["Accounts Receivable", "Application Of Funds(Assets)", "", "", 1, "Receivable", "Asset"],
|
|
||||||
["Stock Expenses", "Expenses", "", "", 0, "Stock Adjustment", "Expense"],
|
|
||||||
["Sample Bank", "Bank Accounts", "", "", 0, "Bank", "Asset"],
|
|
||||||
["Cash", "Cash In Hand", "", "", 0, "Cash", "Asset"],
|
|
||||||
["Stores", "Stock Assets", "", "", 0, "Stock", "Asset"],
|
|
||||||
]
|
|
||||||
|
|
||||||
for row in template:
|
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
|
|
||||||
return writer
|
return writer
|
||||||
@ -453,14 +434,11 @@ def get_mandatory_account_types():
|
|||||||
|
|
||||||
|
|
||||||
def unset_existing_data(company):
|
def unset_existing_data(company):
|
||||||
linked = frappe.db.sql(
|
|
||||||
'''select fieldname from tabDocField
|
|
||||||
where fieldtype="Link" and options="Account" and parent="Company"''',
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# remove accounts data from company
|
# remove accounts data from company
|
||||||
update_values = {d.fieldname: "" for d in linked}
|
|
||||||
|
fieldnames = get_linked_fields("Account").get("Company", {}).get("fieldname", [])
|
||||||
|
linked = [{"fieldname": name} for name in fieldnames]
|
||||||
|
update_values = {d.get("fieldname"): "" for d in linked}
|
||||||
frappe.db.set_value("Company", company, update_values, update_values)
|
frappe.db.set_value("Company", company, update_values, update_values)
|
||||||
|
|
||||||
# remove accounts data from various doctypes
|
# remove accounts data from various doctypes
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
Application Of Funds(Assets),,,,1,,Asset
|
||||||
|
Sources Of Funds(Liabilities),,,,1,,Liability
|
||||||
|
Equity,,,,1,,Equity
|
||||||
|
Expenses,,,,1,Expense Account,Expense
|
||||||
|
Income,,,,1,Income Account,Income
|
||||||
|
Bank Accounts,Application Of Funds(Assets),,,1,Bank,Asset
|
||||||
|
Cash In Hand,Application Of Funds(Assets),,,1,Cash,Asset
|
||||||
|
Stock Assets,Application Of Funds(Assets),,,1,Stock,Asset
|
||||||
|
Cost Of Goods Sold,Expenses,,,0,Cost of Goods Sold,Expense
|
||||||
|
Asset Depreciation,Expenses,,,0,Depreciation,Expense
|
||||||
|
Fixed Assets,Application Of Funds(Assets),,,0,Fixed Asset,Asset
|
||||||
|
Accounts Payable,Sources Of Funds(Liabilities),,,0,Payable,Liability
|
||||||
|
Accounts Receivable,Application Of Funds(Assets),,,1,Receivable,Asset
|
||||||
|
Stock Expenses,Expenses,,,0,Stock Adjustment,Expense
|
||||||
|
Sample Bank,Bank Accounts,,,0,Bank,Asset
|
||||||
|
Cash,Cash In Hand,,,0,Cash,Asset
|
||||||
|
Stores,Stock Assets,,,0,Stock,Asset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user