Skip to content

Commit

Permalink
fix: not able to make material request (backport #36416) (#36426)
Browse files Browse the repository at this point in the history
fix: not able to make material request (#36416)

(cherry picked from commit f83a100)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Jul 31, 2023
1 parent 516191b commit 99e7406
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions erpnext/selling/doctype/sales_order/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def update_item(source, target, source_parent):
# qty is for packed items, because packed items don't have stock_qty field
qty = source.get("qty")
target.project = source_parent.project
target.qty = qty - requested_item_qty.get(source.name, 0) - source.delivered_qty
target.qty = qty - requested_item_qty.get(source.name, 0) - flt(source.get("delivered_qty"))
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)

args = target.as_dict().copy()
Expand Down Expand Up @@ -590,7 +590,7 @@ def update_item(source, target, source_parent):
"doctype": "Material Request Item",
"field_map": {"name": "sales_order_item", "parent": "sales_order"},
"condition": lambda doc: not frappe.db.exists("Product Bundle", doc.item_code)
and (doc.stock_qty - doc.delivered_qty) > requested_item_qty.get(doc.name, 0),
and (doc.stock_qty - flt(doc.get("delivered_qty"))) > requested_item_qty.get(doc.name, 0),
"postprocess": update_item,
},
},
Expand Down
20 changes: 20 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,26 @@ def test_update_child_qty_rate_with_workflow(self):
workflow.is_active = 0
workflow.save()

def test_material_request_for_product_bundle(self):
# Create the Material Request from the sales order for the Packing Items
# Check whether the material request has the correct packing item or not.
if not frappe.db.exists("Item", "_Test Product Bundle Item New 1"):
bundle_item = make_item("_Test Product Bundle Item New 1", {"is_stock_item": 0})
bundle_item.append(
"item_defaults", {"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"}
)
bundle_item.save(ignore_permissions=True)

make_item("_Packed Item New 2", {"is_stock_item": 1})
make_product_bundle("_Test Product Bundle Item New 1", ["_Packed Item New 2"], 2)

so = make_sales_order(
item_code="_Test Product Bundle Item New 1",
)

mr = make_material_request(so.name)
self.assertEqual(mr.items[0].item_code, "_Packed Item New 2")

def test_bin_details_of_packed_item(self):
# test Update Items with product bundle
if not frappe.db.exists("Item", "_Test Product Bundle Item New"):
Expand Down

0 comments on commit 99e7406

Please sign in to comment.