fix: Commonified code and added server side validation
diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js
index f4fd0a2..d46b98b 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.js
+++ b/erpnext/stock/doctype/pick_list/pick_list.js
@@ -38,13 +38,17 @@
};
});
},
- get_item_locations: (frm, save=false) => {
+ set_item_locations:(frm, save) => {
if (!(frm.doc.locations && frm.doc.locations.length)) {
frappe.msgprint(__('Add items in the Item Locations table'));
} else {
frm.call('set_item_locations', {save: save});
}
},
+ get_item_locations: (frm) => {
+ // Button on the form
+ frm.events.set_item_locations(frm, false);
+ },
refresh: (frm) => {
frm.trigger('add_get_items_button');
if (frm.doc.docstatus === 1) {
@@ -106,30 +110,22 @@
frm.trigger('add_get_items_button');
},
create_delivery_note: (frm) => {
- if (!(frm.doc.locations && frm.doc.locations.length)) {
- frappe.msgprint(__('Add items in the Item Locations table'));
- } else {
- frappe.model.open_mapped_doc({
- method: 'erpnext.stock.doctype.pick_list.pick_list.create_delivery_note',
- frm: frm
- });
- }
+ frappe.model.open_mapped_doc({
+ method: 'erpnext.stock.doctype.pick_list.pick_list.create_delivery_note',
+ frm: frm
+ });
},
create_stock_entry: (frm) => {
- if (!(frm.doc.locations && frm.doc.locations.length)) {
- frappe.msgprint(__('Add items in the Item Locations table'));
- } else {
- frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.create_stock_entry', {
- 'pick_list': frm.doc,
- }).then(stock_entry => {
- frappe.model.sync(stock_entry);
- frappe.set_route("Form", 'Stock Entry', stock_entry.name);
- });
- }
+ frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.create_stock_entry', {
+ 'pick_list': frm.doc,
+ }).then(stock_entry => {
+ frappe.model.sync(stock_entry);
+ frappe.set_route("Form", 'Stock Entry', stock_entry.name);
+ });
},
update_pick_list_stock: (frm) => {
- frm.events.get_item_locations(frm, true);
+ frm.events.set_item_locations(frm, true);
},
add_get_items_button: (frm) => {
let purpose = frm.doc.purpose;
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index d7afaf3..616de5e 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -90,6 +90,10 @@
return item_map.values()
+def validate_item_locations(pick_list):
+ if not pick_list.locations:
+ frappe.throw(_("Add items in the Item Locations table"))
+
def get_items_with_location_and_quantity(item_doc, item_location_map):
available_locations = item_location_map.get(item_doc.item_code)
locations = []
@@ -241,6 +245,8 @@
@frappe.whitelist()
def create_delivery_note(source_name, target_doc=None):
pick_list = frappe.get_doc('Pick List', source_name)
+ validate_item_locations(pick_list)
+
sales_orders = [d.sales_order for d in pick_list.locations if d.sales_order]
sales_orders = set(sales_orders)
@@ -300,6 +306,7 @@
@frappe.whitelist()
def create_stock_entry(pick_list):
pick_list = frappe.get_doc(json.loads(pick_list))
+ validate_item_locations(pick_list)
if stock_entry_exists(pick_list.get('name')):
return frappe.msgprint(_('Stock Entry has been already created against this Pick List'))