Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not able to make material request (backport #36416) #36426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading