diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index d52ad5dc3632..b0bbc5d0c71a 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -28,7 +28,18 @@ class TestPurchaseOrder(FrappeTestCase): def test_purchase_order_qty(self): - po = create_purchase_order(qty=-1, do_not_save=True) + po = create_purchase_order(qty=1, do_not_save=True) + po.append( + "items", + { + "item_code": "_Test Item", + "qty": -1, + "rate": 10, + }, + ) + self.assertRaises(frappe.NonNegativeError, po.save) + + po.items[1].qty = 0 self.assertRaises(InvalidQtyError, po.save) def test_make_purchase_receipt(self): diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json index 0b390e542a94..45790b80fcb5 100644 --- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json +++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json @@ -215,6 +215,7 @@ "fieldtype": "Float", "in_list_view": 1, "label": "Quantity", + "non_negative": 1, "oldfieldname": "qty", "oldfieldtype": "Currency", "print_width": "60px", @@ -918,7 +919,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-11-14 18:34:27.267382", + "modified": "2023-11-24 19:07:34.921094", "modified_by": "Administrator", "module": "Buying", "name": "Purchase Order Item", diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 41ef7a3e5a61..f27f8590cd3c 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -902,18 +902,11 @@ def validate_qty_is_not_zero(self): if self.doctype == "Purchase Receipt": return - title = _("Invalid Quantity") for item in self.items: if not flt(item.qty): frappe.throw( msg=_("Row #{0}: Item quantity cannot be zero").format(item.idx), - title=title, - exc=InvalidQtyError, - ) - if flt(item.qty) < 0.0 and self.doctype in ["Purchase Order", "Sales Order"]: - frappe.throw( - msg=_("Row #{0}: Item quantity cannot be negative").format(item.idx), - title=title, + title=_("Invalid Quantity"), exc=InvalidQtyError, ) diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index bf28b2054d5c..9797b6ae11f9 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -200,6 +200,7 @@ "fieldtype": "Float", "in_list_view": 1, "label": "Quantity", + "non_negative": 1, "oldfieldname": "qty", "oldfieldtype": "Currency", "print_width": "100px", @@ -874,7 +875,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2023-11-14 18:37:12.787893", + "modified": "2023-11-24 19:07:17.715231", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item",