mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-14 15:11:52 +00:00
fix: force-delete repost data file during cleanup (backport #57245)
This commit is contained in:
@@ -242,7 +242,7 @@ class RepostItemValuation(Document):
|
|||||||
def clear_attachment(self):
|
def clear_attachment(self):
|
||||||
if attachments := get_attachments(self.doctype, self.name):
|
if attachments := get_attachments(self.doctype, self.name):
|
||||||
attachment = attachments[0]
|
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:
|
if self.reposting_data_file:
|
||||||
self.db_set("reposting_data_file", None)
|
self.db_set("reposting_data_file", None)
|
||||||
|
|||||||
@@ -515,6 +515,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(
|
@ERPNextTestSuite.change_settings(
|
||||||
"Stock Reposting Settings",
|
"Stock Reposting Settings",
|
||||||
{"item_based_reposting": 1, "enable_parallel_reposting": 1, "no_of_parallel_reposting": 2},
|
{"item_based_reposting": 1, "enable_parallel_reposting": 1, "no_of_parallel_reposting": 2},
|
||||||
|
|||||||
Reference in New Issue
Block a user