feat: Add option to create pick list from material request
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index f2fe448..a1cf2f2 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -502,3 +502,24 @@
frappe.throw(_("Productions Orders cannot be raised for:") + '\n' + new_line_sep(errors))
return work_orders
+
+@frappe.whitelist()
+def create_pick_list(source_name, target_doc=None):
+ doc = get_mapped_doc('Material Request', source_name, {
+ 'Material Request': {
+ 'doctype': 'Pick List',
+ 'validation': {
+ 'docstatus': ['=', 1]
+ }
+ },
+ 'Material Request Item': {
+ 'doctype': 'Pick List Reference Item',
+ 'field_map': {
+ 'name': 'material_request_item',
+ 'qty': 'stock_qty'
+ },
+ # 'condition': lambda doc: abs(doc.transferred_qty) < abs(doc.required_qty)
+ },
+ }, target_doc)
+
+ return doc
\ No newline at end of file
diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js
index c2dddab..0f5ba57 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.js
+++ b/erpnext/stock/doctype/pick_list/pick_list.js
@@ -19,6 +19,13 @@
}
};
});
+ frm.set_query('material_request', () => {
+ return {
+ filters: {
+ 'material_request_type': ['=', frm.doc.purpose]
+ }
+ };
+ });
},
refresh: (frm) => {
frm.trigger('add_get_items_button');
@@ -70,6 +77,15 @@
}, __("Select Quantity"), __('Get Items'));
});
},
+ material_request: (frm) => {
+ frm.clear_table('items');
+ frm.clear_table('locations');
+ erpnext.utils.map_current_doc({
+ method: 'erpnext.stock.doctype.material_request.material_request.create_pick_list',
+ target: frm,
+ source_name: frm.doc.material_request
+ });
+ },
purpose: (frm) => {
frm.clear_table('items');
frm.clear_table('locations');
@@ -116,14 +132,4 @@
});
});
}
-});
-
-
-// frappe.ui.form.on('Pick List Reference Item', {
-// item_code: (frm, cdt, cdn) => {
-// let row = locals[cdt][cdn];
-// if (row.item_code) {
-// frappe.xcall('');
-// }
-// }
-// });
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/erpnext/stock/doctype/pick_list/pick_list.json b/erpnext/stock/doctype/pick_list/pick_list.json
index 6eca1c6..91fc6f8 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.json
+++ b/erpnext/stock/doctype/pick_list/pick_list.json
@@ -8,6 +8,7 @@
"purpose",
"customer",
"work_order",
+ "material_request",
"for_qty",
"column_break_4",
"parent_warehouse",
@@ -97,10 +98,17 @@
"fieldtype": "Select",
"label": "Purpose",
"options": "Material Transfer for Manufacture\nMaterial Issue\nMaterial Transfer\nDelivery against Sales Order"
+ },
+ {
+ "depends_on": "eval:['Material Transfer', 'Material Issue'].includes(doc.purpose)",
+ "fieldname": "material_request",
+ "fieldtype": "Link",
+ "label": "Material Request",
+ "options": "Material Request"
}
],
"is_submittable": 1,
- "modified": "2019-08-22 16:58:07.270447",
+ "modified": "2019-08-23 12:34:00.223445",
"modified_by": "Administrator",
"module": "Stock",
"name": "Pick List",
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index 9b8bdfe..a8955de 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -41,6 +41,8 @@
'item_code': item_code,
'sales_order': item_doc.sales_order,
'sales_order_item': item_doc.sales_order_item,
+ 'material_request': item_doc.material_request,
+ 'material_request_item': item_doc.material_request_item,
'uom': item_doc.uom,
'stock_uom': item_doc.stock_uom,
'conversion_factor': item_doc.conversion_factor,
@@ -231,7 +233,6 @@
target.run_method('set_po_nos')
target.run_method('calculate_taxes_and_totals')
-
@frappe.whitelist()
def create_stock_entry(pick_list):
pick_list = frappe.get_doc(json.loads(pick_list))
@@ -282,6 +283,28 @@
return stock_entry.as_dict()
+
+@frappe.whitelist()
+def create_stock_entry_with_material_request_items(pick_list):
+ stock_entry = frappe.new_doc('Stock Entry')
+ stock_entry.pick_list = pick_list.get('name')
+ stock_entry.purpose = pick_list.get('purpose')
+ stock_entry.set_stock_entry_type()
+
+ doc = get_mapped_doc("Work Order", source_name, {
+ "Work Order": {
+ "doctype": "Pick List",
+ "validation": {
+ "docstatus": ["=", 1]
+ }
+ },
+ "Work Order Item": {
+ "doctype": "Pick List Reference Item",
+ "postprocess": update_item_quantity,
+ "condition": lambda doc: abs(doc.transferred_qty) < abs(doc.required_qty)
+ },
+ }, target_doc)
+
@frappe.whitelist()
def get_pending_work_orders(doctype, txt, searchfield, start, page_length, filters, as_dict):
return frappe.db.sql("""
diff --git a/erpnext/stock/doctype/pick_list_item/pick_list_item.json b/erpnext/stock/doctype/pick_list_item/pick_list_item.json
index 9ee806a..0a8f4cb 100644
--- a/erpnext/stock/doctype/pick_list_item/pick_list_item.json
+++ b/erpnext/stock/doctype/pick_list_item/pick_list_item.json
@@ -24,7 +24,9 @@
"batch_no",
"column_break_15",
"sales_order",
- "sales_order_item"
+ "sales_order_item",
+ "material_request",
+ "material_request_item"
],
"fields": [
{
@@ -152,10 +154,21 @@
{
"fieldname": "column_break_20",
"fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "material_request",
+ "fieldtype": "Link",
+ "label": "Material Request",
+ "options": "Material Request"
+ },
+ {
+ "fieldname": "material_request_item",
+ "fieldtype": "Data",
+ "label": "Material Request Item"
}
],
"istable": 1,
- "modified": "2019-08-14 18:41:37.727388",
+ "modified": "2019-08-23 14:13:11.088354",
"modified_by": "Administrator",
"module": "Stock",
"name": "Pick List Item",