diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 09089be861..befde71775 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -770,6 +770,9 @@ class StockController(AccountsController): } ) + if self.docstatus == 2: + force = True + if force or future_sle_exists(args) or repost_required_for_queue(self): item_based_reposting = cint( frappe.db.get_single_value("Stock Reposting Settings", "item_based_reposting") diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py index 96ac4352dc..9c4d997b31 100644 --- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -376,3 +376,19 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin): accounts_settings.acc_frozen_upto = "" accounts_settings.save() + + def test_create_repost_entry_for_cancelled_document(self): + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse="Stores - TCP1", + get_multiple_items=True, + ) + + self.assertTrue(pr.docstatus == 1) + self.assertFalse(frappe.db.exists("Repost Item Valuation", {"voucher_no": pr.name})) + + pr.load_from_db() + + pr.cancel() + self.assertTrue(pr.docstatus == 2) + self.assertTrue(frappe.db.exists("Repost Item Valuation", {"voucher_no": pr.name}))