[Fixes] tax rule, tax rule working even if tax template inside the rule is disabled.

This commit is contained in:
Rohit Waghchaure 2016-05-19 16:53:01 +05:30
parent 1daebc04d0
commit d818bcd888
2 changed files with 15 additions and 1 deletions

View File

@ -3,6 +3,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
@ -19,6 +20,12 @@ def valdiate_taxes_and_charges_template(doc):
where is_default = 1 and name != %s and company = %s""".format(doc.doctype),
(doc.name, doc.company))
validate_disabled(doc)
for tax in doc.get("taxes"):
validate_taxes_and_charges(tax)
validate_inclusive_tax(tax, doc)
def validate_disabled(doc):
if doc.is_default and doc.disabled:
frappe.throw(_("Disabled template must not be default template"))

View File

@ -140,4 +140,11 @@ def get_tax_template(posting_date, args):
if rule.get(key): rule.no_of_keys_matched += 1
rule = sorted(tax_rule, lambda b, a: cmp(a.no_of_keys_matched, b.no_of_keys_matched) or cmp(a.priority, b.priority))[0]
return rule.sales_tax_template or rule.purchase_tax_template
tax_template = rule.sales_tax_template or rule.purchase_tax_template
doctype = "{0} Taxes and Charges Template".format(rule.tax_type)
if frappe.db.get_value(doctype, tax_template, 'disabled')==1:
return None
return tax_template