Skip to content

Commit

Permalink
fix: Use non_negative property in docfield & emove code validation
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Nov 24, 2023
1 parent 619db8a commit c7d7a52
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
13 changes: 12 additions & 1 deletion erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"fieldtype": "Float",
"in_list_view": 1,
"label": "Quantity",
"non_negative": 1,
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"print_width": "60px",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 1 addition & 8 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"fieldtype": "Float",
"in_list_view": 1,
"label": "Quantity",
"non_negative": 1,
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"print_width": "100px",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c7d7a52

Please sign in to comment.