refactor: combine duplicate pick_manually handlers in pick_list.js

This commit is contained in:
Imesha Sudasingha
2025-08-07 05:09:46 +05:30
parent 38c886db8b
commit eebeb36b6c

View File

@@ -81,26 +81,7 @@ frappe.ui.form.on("Pick List", {
}; };
}); });
}, },
pick_manually: (frm) => {
// Clear auto-assigned serial numbers and related fields when switching to manual picking
if (frm.doc.pick_manually && frm.doc.locations) {
let has_changes = false;
frm.doc.locations.forEach((row) => {
if (row.serial_no || row.batch_no || row.serial_and_batch_bundle) {
row.serial_no = "";
row.batch_no = "";
row.serial_and_batch_bundle = "";
row.picked_qty = 0;
has_changes = true;
}
});
if (has_changes) {
frappe.show_alert(__("Cleared auto-assigned serial numbers and batch numbers for manual picking"), 3);
frm.refresh_field("locations");
}
}
},
set_item_locations: (frm, save) => { set_item_locations: (frm, save) => {
if (!(frm.doc.locations && frm.doc.locations.length)) { if (!(frm.doc.locations && frm.doc.locations.length)) {
frappe.msgprint(__("Add items in the Item Locations table")); frappe.msgprint(__("Add items in the Item Locations table"));
@@ -121,11 +102,31 @@ frappe.ui.form.on("Pick List", {
}, },
pick_manually: function (frm) { pick_manually: function (frm) {
// Update warehouse field read-only property
frm.fields_dict.locations.grid.update_docfield_property( frm.fields_dict.locations.grid.update_docfield_property(
"warehouse", "warehouse",
"read_only", "read_only",
!frm.doc.pick_manually !frm.doc.pick_manually
); );
// Clear auto-assigned serial numbers and related fields when switching to manual picking
if (frm.doc.pick_manually && frm.doc.locations) {
let has_changes = false;
frm.doc.locations.forEach((row) => {
if (row.serial_no || row.batch_no || row.serial_and_batch_bundle) {
row.serial_no = "";
row.batch_no = "";
row.serial_and_batch_bundle = "";
row.picked_qty = 0;
has_changes = true;
}
});
if (has_changes) {
frappe.show_alert(__("Cleared auto-assigned serial numbers and batch numbers for manual picking"), 3);
frm.refresh_field("locations");
}
}
}, },
get_item_locations: (frm) => { get_item_locations: (frm) => {