From 24368f3b33ce64ee91ca3c58768cf40b31582c8c Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 31 Jul 2023 19:13:23 +0530 Subject: [PATCH] fix: not able to make material request (#36416) (cherry picked from commit f83a100a8d41de0c539599394d9bf7260fef847b) --- .../doctype/sales_order/sales_order.py | 4 ++-- .../doctype/sales_order/test_sales_order.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 97cccb136202..da838d1b7952 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -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() @@ -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, }, }, diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index 9854f159cfef..ced1ac62729a 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -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"):