Skip to content

Commit cac9073

Browse files
fix: Disallow negative rates in Purchase invoice (backport #54254) (#54393)
fix: Disallow negative rates in Purchase invoice (#54254) (cherry picked from commit 23768ae) Co-authored-by: Nishka Gosalia <58264710+nishkagosalia@users.noreply.github.com>
1 parent 7556550 commit cac9073

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

erpnext/buying/doctype/buying_settings/buying_settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"allow_zero_qty_in_supplier_quotation",
2525
"use_transaction_date_exchange_rate",
2626
"allow_zero_qty_in_request_for_quotation",
27+
"allow_negative_rates_for_items",
2728
"column_break_12",
2829
"maintain_same_rate",
2930
"allow_multiple_items",
@@ -279,6 +280,12 @@
279280
"fieldname": "validate_consumed_qty",
280281
"fieldtype": "Check",
281282
"label": "Validate Consumed Qty (as per BOM)"
283+
},
284+
{
285+
"default": "0",
286+
"fieldname": "allow_negative_rates_for_items",
287+
"fieldtype": "Check",
288+
"label": "Allow Negative rates for Items"
282289
}
283290
],
284291
"grid_page_length": 50,
@@ -288,7 +295,7 @@
288295
"index_web_pages_for_search": 1,
289296
"issingle": 1,
290297
"links": [],
291-
"modified": "2026-03-16 13:28:19.432589",
298+
"modified": "2026-04-15 16:07:35.484787",
292299
"modified_by": "Administrator",
293300
"module": "Buying",
294301
"name": "Buying Settings",

erpnext/buying/doctype/buying_settings/buying_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BuyingSettings(Document):
1818
from frappe.types import DF
1919

2020
allow_multiple_items: DF.Check
21+
allow_negative_rates_for_items: DF.Check
2122
allow_zero_qty_in_purchase_order: DF.Check
2223
allow_zero_qty_in_request_for_quotation: DF.Check
2324
allow_zero_qty_in_supplier_quotation: DF.Check

erpnext/controllers/status_updater.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ def validate_qty(self):
272272
continue
273273

274274
items_to_validate = []
275+
selling_negative_rate_allowed = frappe.get_single_value(
276+
"Selling Settings", "allow_negative_rates_for_items"
277+
)
278+
buying_negative_rate_allowed = frappe.get_single_value(
279+
"Buying Settings", "allow_negative_rates_for_items"
280+
)
275281

276282
# get unique transactions to update
277283
for d in self.get_all_children():
@@ -281,15 +287,24 @@ def validate_qty(self):
281287
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"):
282288
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))
283289

284-
if not frappe.get_single_value("Selling Settings", "allow_negative_rates_for_items"):
290+
if (
291+
not selling_negative_rate_allowed and self.doctype in ["Sales Invoice", "Delivery Note"]
292+
) or (
293+
not buying_negative_rate_allowed
294+
and self.doctype in ["Purchase Invoice", "Purchase Receipt"]
295+
):
285296
if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
286297
frappe.throw(
287298
_(
288299
"For item {0}, rate must be a positive number. To Allow negative rates, enable {1} in {2}"
289300
).format(
290301
frappe.bold(d.item_code),
291302
frappe.bold(_("`Allow Negative rates for Items`")),
292-
get_link_to_form("Selling Settings", "Selling Settings"),
303+
get_link_to_form(
304+
"Selling Settings"
305+
if self.doctype in ["Sales Invoice", "Delivery Note"]
306+
else "Buying Settings"
307+
),
293308
),
294309
)
295310

0 commit comments

Comments
 (0)