Programmatically making a purchase invocie using API

I have hundreds of purchase orders I imported from an old OpenERP installation. How can I, preferably using REST API, make purchase invoices from the PO and also make payments the same way.

Hi @RWEMA_Aimable,

Using make_purchase_invoice, make_purchase_receipt.
More details, kindly check below link

You can write small script and run it on the console
goto frappe-bench and run command bench console.
try below code

from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt, make_purchase_invoice

po = frappe.get_all('Purchase Order', fields = ["name"], filters = {'docstatus': 1, 'per_billed': 0, 'per_received': 0})
for data in po:
	pi = make_purchase_invoice(
	pr = make_purchase_receipt(

Thanks, Rohit

Sorry for the late reply. The codes above runs without error but has no effect. pi.insert() and pi.submit() both return null. When I run the code, which user is it running as? Maybe racking the right permissions?