Hi All ,
I have created purchase order through the sales order , the connection is there but i want the purchase order number in sales order how to fetch it.
Hi All ,
I have created purchase order through the sales order , the connection is there but i want the purchase order number in sales order how to fetch it.
To do that, you need to first create a custom field in the Sales Order similar to the Purchase Order. Then, write a server script to ensure that when a Purchase Order is created from a Sales Order and the Purchase Order is submitted, the Purchase Order ID is set in the Sales Order.
is it possible to take within the connections purchase order ?
No, You have to follow the setup that I provided. and itâs too easy to develop the server script for that.
Yes @NCP, I understood because already I have created 180 sales order so these order donât purchase order number so that only i have asked.
If a purchase order isnât made from a sales order, how can you set. However, if the purchase order is created from the sales order, you can easily configure this using a server script to update the purchase order ID in the sales invoice.
this script is for the purchase order id is configure in sales order right ?
Yes, when you submit the purchase order then id will set in the sales order.
this is working but i want already submitted purchase orders how to fetch the purchase order Id in sales order ?
You have to make a patch and run it for all.
how can I make this
You need to review the patch list in frappe or erpnext and understand how to implement it.
Link: erpnext/erpnext/patches.txt at develop ¡ frappe/erpnext ¡ GitHub
After reviewing, execute the patch.
Alternatively, you can also configure this via a server script. First, add a checkbox field named âUpdate Purchase Order IDâ to the purchase order. Then, set the document event to âAfter Save (Submitted Document)â. Afterward, select multiple purchase orders (Bulk Edit), click edit, choose âUpdate Purchase Order IDâ, and update. Ensure the âUpdate Purchase Order IDâ field is set to âAllow on Submitâ.
Thanks for your updates but in server script bulk update method not working (AFTER SAVE)
Please use âAfter Save (Submitted Document)â event instead of âAfter Saveâ
We tested so it working.
Hi @NCP ,
Thank you so much! This is working well! May I know if it is possible for the Purchase Order Number field to return an array of the doc number instead of only showing the latest Purchase Order?
e.g. i created 2 PO for 1 SO, so i wish the field shows âPO 1, PO 2â instead of showing only PO2.
First, the field must be in the Data fieldtype.
To handle multiple Purchase Orders for a single Sales Order (SO), and ensure that the list is maintained correctly without duplicates, you can update the field to store the Purchase Orders in an array-like format and manage the append operation carefully.
for row in doc.get('items'):
if row.sales_order:
current_po = frappe.db.get_value('Sales Order', row.sales_order, 'purchase_order')
if current_po:
po_list = current_po.split(', ')
else:
po_list = []
if doc.name not in po_list:
po_list.append(doc.name)
updated_po = ', '.join(po_list)
frappe.db.set_value('Sales Order', row.sales_order, 'purchase_order', updated_po)
check it and set it your according.
Thank you so much! This is working well!