fix: not able to make material request (#36416)
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 624dadb..45b3f1d 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -733,7 +733,7 @@
# 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()
@@ -767,7 +767,7 @@
"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 796e258..c85a4fb 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -549,6 +549,26 @@
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"):