From c47cc374411c24c6fb62ca5e8114441e20f78414 Mon Sep 17 00:00:00 2001 From: R-Jayaraman Date: Mon, 3 Aug 2026 16:41:43 +0530 Subject: [PATCH 1/2] fix(opportunity): add validation for positive item quantities --- erpnext/crm/doctype/opportunity/opportunity.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 91ad6018ae8..0c7a6a2cef1 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -133,6 +133,7 @@ class Opportunity(TransactionBase, CRMNote): self.validate_uom_is_integer("uom", "qty") self.validate_cust_name() self.map_fields() + self.validate_qty() self.set_exchange_rate() if not self.title: @@ -143,6 +144,15 @@ class Opportunity(TransactionBase, CRMNote): def on_update(self): self.update_prospect() + def validate_qty(self): + for item in self.items: + if item.qty <= 0: + frappe.throw( + _("Row #{0}: Quantity must be greater than 0 for Item {1}").format( + item.idx, item.item_code + ) + ) + def map_fields(self): for field in self.meta.get_valid_columns(): if not self.get(field) and frappe.db.field_exists(self.opportunity_from, field): From 69de8f2d62c16a96b868885694d6dcc6fd5e5a35 Mon Sep 17 00:00:00 2001 From: R-Jayaraman Date: Tue, 4 Aug 2026 16:38:49 +0530 Subject: [PATCH 2/2] chore: use flt() in qty check --- erpnext/crm/doctype/opportunity/opportunity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 0c7a6a2cef1..79b71818117 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -146,7 +146,7 @@ class Opportunity(TransactionBase, CRMNote): def validate_qty(self): for item in self.items: - if item.qty <= 0: + if flt(item.qty) <= 0: frappe.throw( _("Row #{0}: Quantity must be greater than 0 for Item {1}").format( item.idx, item.item_code