[WORKING] Convert all PO into PR & PI

Hi,

 i need to convert all PO into Pr & Pi via code. I added the following code, to the Purchase_order.py    but am getting an sql error in the for loop. Any idea where i am going wrong? Am using frappe.call () from purchase_order.js



@frappe.whitelist()
def make_purchase_receipt1():
	for e in frappe.db.sql_list("""select name from 'tabPurchase Order' where docstatus = 1"""):

		doc = get_mapped_doc("Purchase Order", e,	{
			"Purchase Order": {
				"doctype": "Purchase Receipt",
				"validation": {
				"docstatus": ["=", 1],
				},
				"field_map":{
					"posting_date": "transaction_date"
				}
			},
			"Purchase Order Item": {
				"doctype": "Purchase Receipt Item",
				"field_map": {
					"name": "prevdoc_detail_docname",
					"parent": "prevdoc_docname",
					"parenttype": "prevdoc_doctype",
				},
				"postprocess": update_item,
				"condition": lambda doc: abs(doc.received_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1
			},
			"Purchase Taxes and Charges": {
				"doctype": "Purchase Taxes and Charges",
				"add_if_empty": True
			}
		}, target_doc, set_missing_values)

How many do you have to convert? Try running this from a command line (paste this in a python module)

Also share your error trace

around 200 . Ok I will try.

Ok I got this working. Helped me with migrating lot of data. I am not sure what the error was. Just rewrote the code and worked.

def make_purchase_receiptall():
	
	mpo = frappe.db.sql_list("""select name from `tabPurchase Order` where docstatus = 1""")
	for i in mpo:
		doc = get_mapped_doc("Purchase Order", i,	{
			"Purchase Order": {
				"doctype": "Purchase Receipt",
				"field_map": {
				"transaction_date": "posting_date"
				
				}
			},
			"Purchase Order Item": {
				"doctype": "Purchase Receipt Item",
				"field_map": {
					"name": "prevdoc_detail_docname",
					"parent": "prevdoc_docname",
					"parenttype": "prevdoc_doctype",
				}
				
			},
			"Purchase Taxes and Charges": {
				"doctype": "Purchase Taxes and Charges",
				"add_if_empty": True
			}
		})

		doc.save()
1 Like