fix: don't allow negative rates (#36027)

* fix: don't allow negative rate

* test: don't allow negative rate

* fix: only check for -rate on items child table
This commit is contained in:
Devin Slauenwhite 2023-08-02 06:56:55 -04:00 committed by GitHub
parent b715453ae3
commit dedf24b86d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -3371,6 +3371,13 @@ class TestSalesInvoice(unittest.TestCase):
set_advance_flag(company="_Test Company", flag=0, default_account="") set_advance_flag(company="_Test Company", flag=0, default_account="")
def test_sales_return_negative_rate(self):
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
self.assertRaises(frappe.ValidationError, si.save)
si.items[0].rate = 10
si.save()
def set_advance_flag(company, flag, default_account): def set_advance_flag(company, flag, default_account):
frappe.db.set_value( frappe.db.set_value(

View File

@ -233,6 +233,9 @@ class StatusUpdater(Document):
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"): if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"):
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code)) frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))
if hasattr(d, "item_code") and hasattr(d, "rate") and d.rate < 0:
frappe.throw(_("For an item {0}, rate must be a positive number").format(d.item_code))
if d.doctype == args["source_dt"] and d.get(args["join_field"]): if d.doctype == args["source_dt"] and d.get(args["join_field"]):
args["name"] = d.get(args["join_field"]) args["name"] = d.get(args["join_field"])