Skip to content

Commit 807d344

Browse files
Merge pull request #50314 from rohitwaghchaure/fixed-stock-reservation-transfer-cancel
fix: stock reservation cancellation for transfer case
2 parents 4e9732a + 1009482 commit 807d344

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

erpnext/manufacturing/doctype/production_plan/production_plan.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,12 @@ def get_reserved_qty_for_production_plan(item_code, warehouse):
19281928
frappe.qb.from_(table)
19291929
.inner_join(child)
19301930
.on(table.name == child.parent)
1931-
.select(Sum(child.quantity * child.conversion_factor))
1931+
.select(
1932+
Sum(
1933+
Case().when(child.quantity == 0, child.required_bom_qty).else_(child.quantity)
1934+
* child.conversion_factor
1935+
)
1936+
)
19321937
.where(
19331938
(table.docstatus == 1)
19341939
& (child.item_code == item_code)

erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ def on_cancel(self) -> None:
109109
self.update_status()
110110
self.update_reserved_stock_in_bin()
111111

112+
def before_cancel(self) -> None:
113+
self.validate_reserved_entries()
114+
115+
def validate_reserved_entries(self):
116+
entries = frappe.get_all(
117+
"Stock Reservation Entry",
118+
fields=["voucher_no as name"],
119+
filters={
120+
"status": "Closed",
121+
"docstatus": 1,
122+
"from_voucher_type": "Purchase Receipt",
123+
"from_voucher_no": self.from_voucher_no,
124+
},
125+
)
126+
127+
if entries:
128+
work_orders = frappe.get_all(
129+
"Work Order",
130+
fields=["name"],
131+
filters={"production_plan": ("in", [entry.name for entry in entries])},
132+
)
133+
134+
frappe.throw(
135+
_(
136+
"Cannot cancel Stock Reservation Entry {0}, as it has used in the work order {1}. Please cancel the work order first or unreserved the stock"
137+
).format(
138+
", ".join([frappe.bold(entry.name) for entry in entries]),
139+
", ".join([frappe.bold(wo.name) for wo in work_orders]),
140+
)
141+
)
142+
112143
def update_unreserved_qty_in_sre(self):
113144
if self.voucher_type == "Delivery Note":
114145
return

0 commit comments

Comments
 (0)