mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-15 15:38:39 +00:00
fix: reject negative tax rate in Item Tax Template
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import flt
|
||||
|
||||
|
||||
class ItemTaxTemplate(Document):
|
||||
@@ -29,6 +30,12 @@ class ItemTaxTemplate(Document):
|
||||
def validate(self):
|
||||
self.set_zero_rate_for_not_applicable_tax()
|
||||
self.validate_tax_accounts()
|
||||
self.validate_tax_rates()
|
||||
|
||||
def validate_tax_rates(self):
|
||||
for row in self.get("taxes"):
|
||||
if flt(row.tax_rate) < 0:
|
||||
frappe.throw(_("Row {0}: Tax Rate cannot be negative").format(row.idx))
|
||||
|
||||
def set_zero_rate_for_not_applicable_tax(self):
|
||||
"""Ensure tax_rate is 0 for any row marked as not applicable."""
|
||||
|
||||
@@ -54,9 +54,6 @@ class TestItemTaxTemplate(ERPNextTestSuite):
|
||||
doc.insert()
|
||||
self.assertEqual(doc.taxes[0].tax_rate, 0)
|
||||
|
||||
def test_negative_tax_rate_is_accepted(self):
|
||||
# SUSPECTED BUG: validate never bounds tax_rate, so a negative (or >100) rate
|
||||
# saves silently. Locking the current (wrong) behaviour.
|
||||
def test_negative_tax_rate_is_rejected(self):
|
||||
doc = self.make_template([(TAX_ACCOUNT, -5, 0)])
|
||||
doc.insert()
|
||||
self.assertEqual(doc.taxes[0].tax_rate, -5)
|
||||
self.assertRaises(frappe.ValidationError, doc.insert)
|
||||
|
||||
Reference in New Issue
Block a user