Set_value on_cancel

I’m trying to write a trigger for an on_cancel action in a custom script, to set explicitly a pair of custom fields for voided check controls. As I understand it, this should bypass the standard validation steps, but I’m not getting anywhere with it.

frappe.ui.form.on("Payment Entry", {
	after_cancel: function(frm) {
		frappe.msgprint("Check " + cur_frm.doc.reference_no + " will be voided.");
		frm.set_value("check_voided_by", frappe.user["name"]);
		frappe.db.set_value("Payment Entry", cur_frm.doc.name, "check_voided_by", frappe.user["name"])
		frm.set_value("voided_on", moment());
		frappe.db.set_value("Payment Entry", cur_frm.doc.name, "voided_on", moment())
		frappe.db.insert(frm.doc);
		frm.refresh();
	}
})

frappe.ui.form.on("Payment Entry", {
	on_trash: function(frm) {
		if(frm.doc.voided_on && frm.doc.reference_date)
			frappe.throw("This transaction cannot be deleted as it is linked to a voided check.")
	}
})
1 Like

Dug a bit in the code for Frappe, there are only some “hooks” that you can use, and after_cancel and on_trash aren’t valid hooks.

So things you need to do to fix this :

Put both the hook calls into one frappe.ui.form.on and change the hook from after_cancel to before_cancel
AFAIK there is no hook for on_trash, You’ll have to change your workflow a bit.

So. For the next person looking to solve this problem, a custom script is not the answer:
Part 1): Payment Entry has “track changes” enabled in the doctype so there’s a record of changes (between saves, submits or cancels) at the bottom of the page. In combination with Part 2, this got us where we needed to be.

Part 2): I decided (with the customer) to change the permissions so that no one, not anybody, not one single person can delete a Payment Entry. Practically, this means that cancelled paper checks have a matching number in the system.

An electronic record of paper checks now exists and there is an audit trail. Payment Entries can be deleted from draft state (good, people make mistakes) but not after a check number has been committed to the record with a submit (also good).

@tmatteson , sorry to bring back a closed topic here but I have a quick question on voided/reprinted checks. Let’s say a supplier never received their original check so we need to void that check and print a new one. How are you actually voiding the original check so that it no longer shows on the Bank Reconciliation report? We’ve had three checks we did this with in 2018 and all three still show on the report as uncashed, which is true, because the replacement checks were cashed. Trying to figure out proper voiding process in this situation.

I would cancel those Payment Entries and add a comment noting the replace check number and document reference.
In the future, I would cancel and amend with the replacement check number, but if you’ve started a new document, thats effectively the same and not wrong, but less good because it’s less easy to audit.

Thanks for the suggestions. I don’t know if we’ve already created too much of mess or not… Our checks were issued in one month and then we found out they never received them the following month. Here’s the process we did:

  1. Issued check in November via payment entry and allocated to 10 invoices.
  2. Entered journal entry in December to credit the amount back to AP/debit bank account when discovered check never arrived.
  3. Issued check in December via payment entry and allocated to the JV in step 2.
  4. 2nd check was cashed in December and we reconciled it with proper date.

On our bank reconciliation statement, we still see the original check as uncleared, which is true. My concern is that I’m not balancing and I can’t figure out what step I need to backtrack to.

I also can’t find any other info on the forums about voiding/cancelling checks and what the proper process is. Thanks for any guidance!

Does anyone with #accounts experience know how to handle this situation? The checks that were voided/cancelled are still showing up on our bank reconciliation statement as uncleared. We have already issued new checks and those have been reconciled. How can we remove these checks from showing uncleared but keep the invoices those are allocated to still marked as paid?