fix: add item taxes at the same times as sales and purchase taxes

This commit is contained in:
Florian HENRY 2021-02-24 21:45:29 +01:00
parent 684fc4e27b
commit e11ce57f3c
2 changed files with 23 additions and 1 deletions

View File

@ -140,7 +140,7 @@ frappe.ui.form.on("Company", {
doc: frm.doc,
freeze: true,
callback: function() {
frappe.msgprint(__("Default tax templates for sales and purchase are created."));
frappe.msgprint(__("Default tax templates for sales, purchase and items are created."));
}
})
},

View File

@ -29,6 +29,7 @@ def make_tax_account_and_template(company, account_name, tax_rate, template_name
try:
if accounts:
make_sales_and_purchase_tax_templates(accounts, template_name)
make_item_tax_templates(accounts, template_name)
except frappe.NameError:
if frappe.message_log: frappe.message_log.pop()
except RootNotEditable:
@ -84,6 +85,27 @@ def make_sales_and_purchase_tax_templates(accounts, template_name=None):
doc = frappe.get_doc(purchase_tax_template)
doc.insert(ignore_permissions=True)
def make_item_tax_templates(accounts, template_name=None):
if not template_name:
template_name = accounts[0].name
item_tax_template = {
"doctype": "Item Tax Template",
"title": template_name,
"company": accounts[0].company,
'taxes': []
}
for account in accounts:
item_tax_template['taxes'].append({
"tax_type": account.name,
"tax_rate": account.tax_rate
})
# Items
frappe.get_doc(copy.deepcopy(item_tax_template)).insert(ignore_permissions=True)
def get_tax_account_group(company):
tax_group = frappe.db.get_value("Account",
{"account_name": "Duties and Taxes", "is_group": 1, "company": company})