mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 04:59:18 +00:00
Merge pull request #39768 from frappe/mergify/bp/version-15-hotfix/pr-39764
fix: remove file from the disk after the completion of reposting (backport #39764)
This commit is contained in:
@@ -286,6 +286,7 @@ def repost(doc):
|
|||||||
repost_gl_entries(doc)
|
repost_gl_entries(doc)
|
||||||
|
|
||||||
doc.set_status("Completed")
|
doc.set_status("Completed")
|
||||||
|
remove_attached_file(doc.name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
@@ -314,6 +315,13 @@ def repost(doc):
|
|||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def remove_attached_file(docname):
|
||||||
|
if file_name := frappe.db.get_value(
|
||||||
|
"File", {"attached_to_name": docname, "attached_to_doctype": "Repost Item Valuation"}, "name"
|
||||||
|
):
|
||||||
|
frappe.delete_doc("File", file_name, delete_permanently=True)
|
||||||
|
|
||||||
|
|
||||||
def repost_sl_entries(doc):
|
def repost_sl_entries(doc):
|
||||||
if doc.based_on == "Transaction":
|
if doc.based_on == "Transaction":
|
||||||
repost_future_sle(
|
repost_future_sle(
|
||||||
|
|||||||
@@ -424,3 +424,38 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin):
|
|||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, riv.save)
|
self.assertRaises(frappe.ValidationError, riv.save)
|
||||||
doc.cancel()
|
doc.cancel()
|
||||||
|
|
||||||
|
def test_remove_attached_file(self):
|
||||||
|
item_code = make_item("_Test Remove Attached File Item", properties={"is_stock_item": 1})
|
||||||
|
|
||||||
|
make_purchase_receipt(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
pr1 = make_purchase_receipt(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=1,
|
||||||
|
rate=100,
|
||||||
|
posting_date=add_days(today(), days=-1),
|
||||||
|
)
|
||||||
|
|
||||||
|
if docname := frappe.db.exists("Repost Item Valuation", {"voucher_no": pr1.name}):
|
||||||
|
self.assertFalse(
|
||||||
|
frappe.db.get_value(
|
||||||
|
"File",
|
||||||
|
{"attached_to_doctype": "Repost Item Valuation", "attached_to_name": docname},
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
repost_entries = create_item_wise_repost_entries(pr1.doctype, pr1.name)
|
||||||
|
for entry in repost_entries:
|
||||||
|
self.assertFalse(
|
||||||
|
frappe.db.get_value(
|
||||||
|
"File",
|
||||||
|
{"attached_to_doctype": "Repost Item Valuation", "attached_to_name": entry.name},
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user