refactor: remove references in repost doctypes upon parent doc delet
This commit is contained in:
parent
61c6ebbb95
commit
ed7f67b1a8
@ -55,7 +55,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-07-27 15:47:58.975034",
|
||||
"modified": "2023-09-26 14:21:27.362567",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Repost Accounting Ledger",
|
||||
@ -77,5 +77,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
@ -99,7 +99,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-08 07:38:40.079038",
|
||||
"modified": "2023-09-26 14:21:35.719727",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Repost Payment Ledger",
|
||||
@ -155,5 +155,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
@ -243,13 +243,38 @@ class AccountsController(TransactionBase):
|
||||
_doc.cancel()
|
||||
_doc.delete()
|
||||
|
||||
def on_trash(self):
|
||||
# delete references in 'Repost Payment Ledger'
|
||||
rpi = frappe.qb.DocType("Repost Payment Ledger Items")
|
||||
frappe.qb.from_(rpi).delete().where(
|
||||
(rpi.voucher_type == self.doctype) & (rpi.voucher_no == self.name)
|
||||
).run()
|
||||
def _remove_references_in_repost_doctypes(self):
|
||||
repost_doctypes = ["Repost Payment Ledger Items", "Repost Accounting Ledger Items"]
|
||||
|
||||
for _doctype in repost_doctypes:
|
||||
dt = frappe.qb.DocType(_doctype)
|
||||
rows = (
|
||||
frappe.qb.from_(dt)
|
||||
.select(dt.name, dt.parent, dt.parenttype)
|
||||
.where((dt.voucher_type == self.doctype) & (dt.voucher_no == self.name))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
if rows:
|
||||
references_map = frappe._dict()
|
||||
for x in rows:
|
||||
references_map.setdefault((x.parenttype, x.parent), []).append(x.name)
|
||||
|
||||
for doc, rows in references_map.items():
|
||||
repost_doc = frappe.get_doc(doc[0], doc[1])
|
||||
|
||||
for row in rows:
|
||||
if _doctype == "Repost Payment Ledger Items":
|
||||
repost_doc.remove(repost_doc.get("repost_vouchers", {"name": row})[0])
|
||||
else:
|
||||
repost_doc.remove(repost_doc.get("vouchers", {"name": row})[0])
|
||||
|
||||
repost_doc.flags.ignore_validate_update_after_submit = True
|
||||
repost_doc.flags.ignore_links = True
|
||||
repost_doc.save(ignore_permissions=True)
|
||||
|
||||
def on_trash(self):
|
||||
self._remove_references_in_repost_doctypes()
|
||||
self._remove_references_in_unreconcile()
|
||||
|
||||
# delete sl and gl entries on deletion of transaction
|
||||
|
Loading…
Reference in New Issue
Block a user