Bulk Amend Transaction


In our production environment by mistake, one user canceled all payment entry and we have database backup but that is 4days old so we can not restore that.

I write the below script to amend all and resubmit that again. Does anyone have any other solution that I should follow?

for pe in frappe.get_all("Payment Entry",filters={},fields=["name"]):


            pe_data = frappe.get_doc("Payment Entry", pe.name)

            amended_doc = frappe.copy_doc(pe_data)

            amended_doc.update({"amended_from": pe_data.name})


        except Exception as e:

            print("Error In {0}".format(pe.name))

            frappe.log_error(frappe.get_traceback(), _("Bulk Amend Error"))