Skip to content

Commit

Permalink
Merge pull request #35070 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-35066

fix: don't create material request from sales order against delivered items (backport #35066)
  • Loading branch information
rohitwaghchaure authored Apr 28, 2023
2 parents 8571e6c + a5489ee commit 5f381cd
Show file tree
Hide file tree
Showing 2 changed files with 33 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 @@ -547,7 +547,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)
target.qty = qty - requested_item_qty.get(source.name, 0) - source.delivered_qty
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)

args = target.as_dict().copy()
Expand Down Expand Up @@ -581,7 +581,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 > requested_item_qty.get(doc.name, 0),
and (doc.stock_qty - doc.delivered_qty) > requested_item_qty.get(doc.name, 0),
"postprocess": update_item,
},
},
Expand Down
31 changes: 31 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,37 @@ def test_sales_order_partial_advance_payment(self):
self.assertEqual(pe.references[1].reference_name, so.name)
self.assertEqual(pe.references[1].allocated_amount, 300)

def test_delivered_item_material_request(self):
"SO -> MR (Manufacture) -> WO. Test if WO Qty is updated in SO."
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as make_se_from_wo,
)
from erpnext.stock.doctype.material_request.material_request import raise_work_orders

so = make_sales_order(
item_list=[
{"item_code": "_Test FG Item", "qty": 10, "rate": 100, "warehouse": "Work In Progress - _TC"}
]
)

make_stock_entry(
item_code="_Test FG Item", target="Work In Progress - _TC", qty=4, basic_rate=100
)

dn = make_delivery_note(so.name)
dn.items[0].qty = 4
dn.submit()

so.load_from_db()
self.assertEqual(so.items[0].delivered_qty, 4)

mr = make_material_request(so.name)
mr.material_request_type = "Purchase"
mr.schedule_date = today()
mr.save()

self.assertEqual(mr.items[0].qty, 6)


def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
Expand Down

0 comments on commit 5f381cd

Please sign in to comment.