chore: delete comments and unlink attachments on company transactions deletion (backport #38077) (#38079)
* chore: delete comments and unlink attachments on company transactions deletion (cherry picked from commit 2f9e96e3245e210ab1a26ffe99499367b0e0afa5) * fix: unrelated transation date typo (cherry picked from commit b097bb20d99f1d25fbd8bdcf0277859741a0ee53) --------- Co-authored-by: anandbaburajan <anandbaburajan@gmail.com>
This commit is contained in:
parent
6d325a40a1
commit
4fdd1ec498
@ -365,7 +365,7 @@ class BuyingController(SubcontractingController):
|
||||
{
|
||||
"item_code": d.item_code,
|
||||
"warehouse": d.get("from_warehouse"),
|
||||
"posting_date": self.get("posting_date") or self.get("transation_date"),
|
||||
"posting_date": self.get("posting_date") or self.get("transaction_date"),
|
||||
"posting_time": posting_time,
|
||||
"qty": -1 * flt(d.get("stock_qty")),
|
||||
"serial_and_batch_bundle": d.get("serial_and_batch_bundle"),
|
||||
|
@ -108,7 +108,16 @@ class TransactionDeletionRecord(Document):
|
||||
|
||||
if no_of_docs > 0:
|
||||
self.delete_version_log(docfield["parent"], docfield["fieldname"])
|
||||
self.delete_communications(docfield["parent"], docfield["fieldname"])
|
||||
|
||||
reference_docs = frappe.get_all(
|
||||
docfield["parent"], filters={docfield["fieldname"]: self.company}
|
||||
)
|
||||
reference_doc_names = [r.name for r in reference_docs]
|
||||
|
||||
self.delete_communications(docfield["parent"], reference_doc_names)
|
||||
self.delete_comments(docfield["parent"], reference_doc_names)
|
||||
self.unlink_attachments(docfield["parent"], reference_doc_names)
|
||||
|
||||
self.populate_doctypes_table(tables, docfield["parent"], no_of_docs)
|
||||
|
||||
self.delete_child_tables(docfield["parent"], docfield["fieldname"])
|
||||
@ -197,19 +206,49 @@ class TransactionDeletionRecord(Document):
|
||||
(versions.ref_doctype == doctype) & (versions.docname.isin(batch))
|
||||
).run()
|
||||
|
||||
def delete_communications(self, doctype, company_fieldname):
|
||||
reference_docs = frappe.get_all(doctype, filters={company_fieldname: self.company})
|
||||
reference_doc_names = [r.name for r in reference_docs]
|
||||
|
||||
def delete_communications(self, doctype, reference_doc_names):
|
||||
communications = frappe.get_all(
|
||||
"Communication",
|
||||
filters={"reference_doctype": doctype, "reference_name": ["in", reference_doc_names]},
|
||||
)
|
||||
communication_names = [c.name for c in communications]
|
||||
|
||||
if not communication_names:
|
||||
return
|
||||
|
||||
for batch in create_batch(communication_names, self.batch_size):
|
||||
frappe.delete_doc("Communication", batch, ignore_permissions=True)
|
||||
|
||||
def delete_comments(self, doctype, reference_doc_names):
|
||||
comments = frappe.get_all(
|
||||
"Comment",
|
||||
filters={"reference_doctype": doctype, "reference_name": ["in", reference_doc_names]},
|
||||
)
|
||||
comment_names = [c.name for c in comments]
|
||||
|
||||
if not comment_names:
|
||||
return
|
||||
|
||||
for batch in create_batch(comment_names, self.batch_size):
|
||||
frappe.delete_doc("Comment", batch, ignore_permissions=True)
|
||||
|
||||
def unlink_attachments(self, doctype, reference_doc_names):
|
||||
files = frappe.get_all(
|
||||
"File",
|
||||
filters={"attached_to_doctype": doctype, "attached_to_name": ["in", reference_doc_names]},
|
||||
)
|
||||
file_names = [c.name for c in files]
|
||||
|
||||
if not file_names:
|
||||
return
|
||||
|
||||
file = qb.DocType("File")
|
||||
|
||||
for batch in create_batch(file_names, self.batch_size):
|
||||
qb.update(file).set(file.attached_to_doctype, None).set(file.attached_to_name, None).where(
|
||||
file.name.isin(batch)
|
||||
).run()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_doctypes_to_be_ignored():
|
||||
|
Loading…
x
Reference in New Issue
Block a user