fix: prevent deleting repost queue for cancelled transactions

This commit is contained in:
Ankush Menat 2022-04-08 13:20:25 +05:30 committed by Ankush Menat
parent 617deda2ff
commit a281998bcb
2 changed files with 17 additions and 1 deletions

View File

@ -61,6 +61,22 @@ class RepostItemValuation(Document):
repost(self)
def before_cancel(self):
self.check_pending_repost_against_cancelled_transaction()
def check_pending_repost_against_cancelled_transaction(self):
if self.status not in ("Queued", "In Progress"):
return
if not (self.voucher_no and self.voucher_no):
return
transaction_status = frappe.db.get_value(self.voucher_type, self.voucher_no, "docstatus")
if transaction_status == 2:
msg = _("Cannot cancel as processing of cancelled documents is pending.")
msg += "<br>" + _("Please try again in an hour.")
frappe.throw(msg, title=_("Pending processing"))
@frappe.whitelist()
def restart_reposting(self):
self.set_status("Queued", write=False)

View File

@ -178,9 +178,9 @@ def validate_cancellation(args):
)
if repost_entry.status == "Queued":
doc = frappe.get_doc("Repost Item Valuation", repost_entry.name)
doc.status = "Skipped"
doc.flags.ignore_permissions = True
doc.cancel()
doc.delete()
def set_as_cancel(voucher_type, voucher_no):