Skip to content

Commit

Permalink
fix: Supplied Qty not updated on Stock Entry cancel
Browse files Browse the repository at this point in the history
- Loop over PO supplied items and update them as data from SE will exclude a row if supplied qty becomes 0 on cancel
- Use DB API insteaf of raw SQL

(cherry picked from commit fa1d9d5)
  • Loading branch information
marination authored and mergify[bot] committed Jun 13, 2022
1 parent 5d0f271 commit 79b2062
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,23 +1979,30 @@ def update_purchase_order_supplied_items(self):
):

# Get PO Supplied Items Details
item_wh = frappe._dict(
frappe.db.sql(
"""
select rm_item_code, reserve_warehouse
from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
where po.name = poitemsup.parent
and po.name = %s""",
self.purchase_order,
)
po_supplied_items = frappe.db.get_all(
"Purchase Order Item Supplied",
filters={"parent": self.purchase_order},
fields=["name", "rm_item_code", "reserve_warehouse"],
)

# Get Items Supplied in Stock Entries against PO
supplied_items = get_supplied_items(self.purchase_order)
for name, item in supplied_items.items():
frappe.db.set_value("Purchase Order Item Supplied", name, item)

# Update reserved sub contracted quantity in bin based on Supplied Item Details and
for row in po_supplied_items:
key, item = row.name, {}
if not supplied_items.get(key):
# no stock transferred against PO Supplied Items row
item = {"supplied_qty": 0, "returned_qty": 0, "total_supplied_qty": 0}
else:
item = supplied_items.get(key)

frappe.db.set_value("Purchase Order Item Supplied", row.name, item)

# RM Item-Reserve Warehouse Dict
item_wh = {x.get("rm_item_code"): x.get("reserve_warehouse") for x in po_supplied_items}

for d in self.get("items"):
# Update reserved sub contracted quantity in bin based on Supplied Item Details and
item_code = d.get("original_item") or d.get("item_code")
reserve_warehouse = item_wh.get(item_code)
if not (reserve_warehouse and item_code):
Expand Down

0 comments on commit 79b2062

Please sign in to comment.