From caa4f331694937a6768fa3180562e947d6996e7f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:13:22 +0530 Subject: [PATCH] fix: don't allow negative rate (backport #36027) (#36465) * 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 (cherry picked from commit dedf24b86db824f84dd48cf2b470272aa90ab636) # Conflicts: # erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py * chore: resolve merge conflict --------- Co-authored-by: Devin Slauenwhite Co-authored-by: ruthra kumar --- .../accounts/doctype/sales_invoice/test_sales_invoice.py | 7 +++++++ erpnext/controllers/status_updater.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 856631ee657..fd5ca8b1eba 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3316,6 +3316,13 @@ class TestSalesInvoice(unittest.TestCase): ) self.assertRaises(frappe.ValidationError, si.submit) + 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 get_sales_invoice_for_e_invoice(): si = make_sales_invoice_for_ewaybill() diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 58cab147a47..a4bc4a9c69e 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -233,6 +233,9 @@ class StatusUpdater(Document): 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)) + 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"]): args["name"] = d.get(args["join_field"])