Skip to content

Commit

Permalink
fix: on closed unreserved the production plan qty (backport #38848) (#…
Browse files Browse the repository at this point in the history
…38859)

fix: on closed unreserved the production plan qty (#38848)

(cherry picked from commit 2184e8e)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
(cherry picked from commit 5e68b7e)
  • Loading branch information
mergify[bot] committed Dec 19, 2023
1 parent 7320440 commit f16574e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def set_status(self, close=None):

if close:
self.db_set("status", "Closed")
self.update_bin_qty()
return

if self.total_produced_qty > 0:
Expand All @@ -597,6 +598,9 @@ def set_status(self, close=None):
if close is not None:
self.db_set("status", self.status)

if self.docstatus == 1 and self.status != "Completed":
self.update_bin_qty()

def update_ordered_status(self):
update_status = False
for d in self.po_items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,47 @@ def test_material_request_qty_purchase_and_material_transfer(self):
self.assertEqual(row.get("uom"), "Nos")
self.assertEqual(row.get("conversion_factor"), 10.0)

def test_unreserve_qty_on_closing_of_pp(self):
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
from erpnext.stock.utils import get_or_make_bin

fg_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name
rm_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name

store_warehouse = create_warehouse("Store Warehouse", company="_Test Company")
rm_warehouse = create_warehouse("RM Warehouse", company="_Test Company")

make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")

pln = create_production_plan(
item_code=fg_item, planned_qty=10, stock_uom="_Test UOM 1", do_not_submit=1
)

pln.for_warehouse = rm_warehouse
mr_items = get_items_for_material_requests(pln.as_dict())
for d in mr_items:
pln.append("mr_items", d)

pln.save()
pln.submit()

bin_name = get_or_make_bin(rm_item, rm_warehouse)
before_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))

pln.reload()
pln.set_status(close=True)

bin_name = get_or_make_bin(rm_item, rm_warehouse)
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
self.assertAlmostEqual(after_qty, before_qty - 10)

pln.reload()
pln.set_status(close=False)

bin_name = get_or_make_bin(rm_item, rm_warehouse)
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
self.assertAlmostEqual(after_qty, before_qty)


def create_production_plan(**args):
"""
Expand Down

0 comments on commit f16574e

Please sign in to comment.