PO - Insert items with supplier part number - Customization support
Purchase departments always need to enter PO through supplier part numbers as it is the most know. We can do that with basic customization on ERPNext PO - Insert items with supplier part number -
ERPNext have already featured the use of barcodes to auto-populate items table
in Purchase Order doctype. In this article, we discuss about populating the items
table based on Supplier part number. Once Supplier part number field is updated
in item master, items linked with it, are automatically fetched and displayed in the
table.
Firstly, you need to create a field with name ‘Supplier Part Number’ in your
Purchase Order doctype. Once you complete that we need to fetch necessary
data to be filled in Items table. For that, move to your source code editor and
create a file utils.py and write a python function to extract data from the database.
-----------------------------------------
@frappe.whitelist()
def get_items(code):
items=frappe.db.sql(f"""SELECT parent FROM `tabItem Supplier` WHERE
supplier_part_no='{code}';""",as_dict=True)
i=0
item_details=[]
for item in items:
itemm=(items[i].parent)
item_detail=frappe.db.sql(f"""SELECT
item_code,item_name,stock_uom,valuation_rate,description FROM `tabItem` WHERE
item_code='{itemm}';""",as_dict=True)
item_details.append(item_detail)
i+=1
return item_details
---------------------------------------
Once you finish collecting data, we need to append these data to our items
table. This can be achieved by, running a client script. Firstly, Create a client
script for Purchase Order doctype. You must make sure that the client script is
enabled , so that it works properly. Now, extract data returned by python
function by performing a Frappe ajax call. Parse and filter the data received
and populate the items table using the required parameters.
frappe.ui.form.on('Purchase Order', {
supplier_part_number:function(frm) {
let supplier_part_no =frm.doc.supplier_part_number
if(supplier_part_no) {
frappe.call({
method:"test_app.utils.get_items", args:{code:supplier_part_no}
}).done((r)=> {
frm.doc.items=[]
$.each(r.message,function(_i, e){
for (let i=0;i<e.length;i++){
let entry=frm.add_child("items");
entry.item_code=e[i].item_code;
entry.item_name=e[i].item_name;
entry.uom=e[i].stock_uom;
entry.rate=e[i].valuation_rate;
entry.description=e[i].description;
entry.supplier_part_no=supplier_part_no;
}
})
refresh_field("items")
})
}}
})
Now you can see the supplier item code field inside the Purchase order form like show below and type any supplier part number and it will populate in the item table.
Please contact use support@erpgulf.com for any clarifications or details.
Hiba Nazar
Hiba works on API and Integrations.
No comments yet. Start a new discussion.