Programmatically Cancel + Amend + Save a DocType

Hey all,

I am searching to find the following:

I have a submited Purchase Receipt with some items ex. pr = frappe.get_doc("Purchase Receipt", "PREC-00024")

From Erpnext UI, one can : “Cancel” the “PREC-00024”, “Amend” with new “PREC-00024-1” (amend adding/removing items with the creation of new record “old_name-1”) and Save “PREC-00024-1”.

I need this process programmatically.


@kickapoo: please review Routine to save a document for more information on how to save your document in a programmatic way.

As for cancel, please review along the lines in Frappe method to cancel a document

Hi try something in this way
pr.cancel() new_pr = frappe.copy_doc(pr) new_pr.amended_from = new_pr.status = "Draft" new_pr.insert()

1 Like

@gvyshnya Ty for the answer

@SwitsolAG Ty, that did the trick. I was missing copy_doc :frowning:

1 Like