Skip to content

Commit

Permalink
fix: fetching items from blanket order to sales/purchase order (#45262)
Browse files Browse the repository at this point in the history
* fix: blanket order with zero item quantity

* fix: item quantity validation

* refactor: resolve linter issue

(cherry picked from commit 98d401b)
  • Loading branch information
diptanilsaha authored and mergify[bot] committed Jan 17, 2025
1 parent c789171 commit 7fc19e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions erpnext/manufacturing/doctype/blanket_order/blanket_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BlanketOrder(Document):
def validate(self):
self.validate_dates()
self.validate_duplicate_items()
self.validate_item_qty()
self.set_party_item_code()

def validate_dates(self):
Expand Down Expand Up @@ -117,6 +118,11 @@ def update_ordered_qty(self):
for d in self.items:
d.db_set("ordered_qty", item_ordered_qty.get(d.item_code, 0))

def validate_item_qty(self):
for d in self.items:
if d.qty < 0:
frappe.throw(_("Row {0}: Quantity cannot be negative.").format(d.idx))


@frappe.whitelist()
def make_order(source_name):
Expand Down Expand Up @@ -148,7 +154,7 @@ def update_item(source, target, source_parent):
"doctype": doctype + " Item",
"field_map": {"rate": "blanket_order_rate", "parent": "blanket_order"},
"postprocess": update_item,
"condition": lambda item: (flt(item.qty) - flt(item.ordered_qty)) > 0,
"condition": lambda item: not (flt(item.qty)) or (flt(item.qty) - flt(item.ordered_qty)) > 0,
},
},
)
Expand Down Expand Up @@ -186,7 +192,7 @@ def validate_against_blanket_order(order_doc):
if item.item_code in item_data:
remaining_qty = item.qty - item.ordered_qty
allowed_qty = remaining_qty + (remaining_qty * (allowance / 100))
if allowed_qty < item_data[item.item_code]:
if item.qty and allowed_qty < item_data[item.item_code]:
frappe.throw(
_(
"Item {0} cannot be ordered more than {1} against Blanket Order {2}."
Expand Down

0 comments on commit 7fc19e1

Please sign in to comment.