From 1aee0df79ac7b7479f0056f6660b938096f3d540 Mon Sep 17 00:00:00 2001 From: kaulith <64089478+kaulith@users.noreply.github.com> Date: Fri, 17 Jul 2026 22:07:20 +0530 Subject: [PATCH] fix: force-delete repost data file during cleanup (#57245) * fix(stock): force-delete repost data file during cleanup * test(stock): cover repost data file cleanup with attach guard --- .../repost_item_valuation.py | 2 +- .../test_repost_item_valuation.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 9993250bc87..c02bdd6259e 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -251,7 +251,7 @@ class RepostItemValuation(Document): def clear_attachment(self): if attachments := get_attachments(self.doctype, self.name): attachment = attachments[0] - frappe.delete_doc("File", attachment.name, ignore_permissions=True) + frappe.delete_doc("File", attachment.name, ignore_permissions=True, force=True) if self.reposting_data_file: self.db_set("reposting_data_file", None) 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 725f9d9c9da..5c5aabf2d85 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 @@ -688,6 +688,34 @@ class TestRepostItemValuation(ERPNextTestSuite, StockTestMixin): ) ) + def test_clear_attachment_skips_referenced_data_file(self): + riv = frappe.get_doc( + { + "doctype": "Repost Item Valuation", + "based_on": "Item and Warehouse", + "company": "_Test Company", + "item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC", + "posting_date": today(), + } + ).insert(ignore_permissions=True) + + attached = frappe.get_doc( + { + "doctype": "File", + "file_name": "repost_data.json.gz", + "content": "test", + "attached_to_doctype": riv.doctype, + "attached_to_name": riv.name, + } + ).insert(ignore_permissions=True) + riv.db_set("reposting_data_file", attached.file_url) + + riv.clear_attachment() + + self.assertFalse(frappe.db.exists("File", attached.name)) + self.assertIsNone(frappe.db.get_value("Repost Item Valuation", riv.name, "reposting_data_file")) + @ERPNextTestSuite.change_settings( "Stock Reposting Settings", {"item_based_reposting": 1, "enable_parallel_reposting": 1, "no_of_parallel_reposting": 2},