Hi
It seems serial number for item when doing a purchase receipt is not working properly.
Automatic assignment is working, but if you have to enter the item serial number by hand, it
does not work.
I am trying to write my own script to handle this and I believe I am almost there but would like to ask for assistance for the last bit.
Use case:
Add a custom button in the “Items” table.
Select the row where the item requires a serial number.
Click the button.
New “Serial No” document is created and auto-populates item_code and document numbers on
the new Serial No doc
User enters the serial number for the item on the new Serial No doc
When saving the Serial No doc, newly created serial number is visible in items table of Pur-Receipt.
Here is my code…
rappe.ui.form.on('Purchase Receipt', {
refresh: function(frm) {
if (frm.doc.docstatus === 0) {
// frappe.show_alert(frm.doc.supplier_name, 5);
frm.fields_dict['items'].grid.add_custom_button(__('Create Serial Number'), function(doc) {
var selected_item = frm.fields_dict['items'].grid.get_selected_children()[0]; // Get the selected row
if (selected_item && !selected_item.serial_no) {
frappe.show_alert(selected_item.item_code, 5);
var newDoc = frappe.new_doc('Serial No');
newDoc.item_code = selected_item.item_code;
// Set any other fields as needed
frm.refresh();
// frappe.ui.form.save_single(newDoc);
}
});
}
}
});
My code created the a new Serial No document but the item_code field is not auto-populated.
The show_alerts are just for debugging.
I would like to ask for asisstance so that I can compete this.
Thank you