Merge pull request #24735 from FHenry/fix_create_item_tax_with_salespurchasetax

fix: add item taxes at the same times as sales and purchase taxes
This commit is contained in:
Deepesh Garg 2021-03-01 20:52:42 +05:30 committed by GitHub
commit f45756d821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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})