Compare commits

...

1 Commits

Author SHA1 Message Date
Nabin Hait
5769c86391 fix: reject negative tax rate in Item Tax Template 2026-07-03 14:13:49 +05:30
2 changed files with 9 additions and 5 deletions

View File

@@ -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."""

View File

@@ -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)