Added make Production Order button against Material Request
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index ad8b776..399d576 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -139,16 +139,18 @@
},
set_default_warehouse: function(frm) {
- frappe.call({
- method: "erpnext.manufacturing.doctype.production_order.production_order.get_default_warehouse",
+ if (!(frm.doc.wip_warehouse || frm.doc.fg_warehouse)) {
+ frappe.call({
+ method: "erpnext.manufacturing.doctype.production_order.production_order.get_default_warehouse",
- callback: function(r) {
- if(!r.exe) {
- frm.set_value("wip_warehouse", r.message.wip_warehouse);
- frm.set_value("fg_warehouse", r.message.fg_warehouse)
+ callback: function(r) {
+ if(!r.exe) {
+ frm.set_value("wip_warehouse", r.message.wip_warehouse);
+ frm.set_value("fg_warehouse", r.message.fg_warehouse)
+ }
}
- }
- });
+ });
+ }
}
}
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 922eb5a..29968d8 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -52,7 +52,11 @@
if(doc.material_request_type === "Purchase")
cur_frm.add_custom_button(__("Supplier Quotation"),
this.make_supplier_quotation, __("Make"));
-
+
+ if(doc.material_request_type === "Manufacture" && doc.status === "Submitted")
+ cur_frm.add_custom_button(__("Production Order"),
+ this.make_production_order, __("Make"));
+
cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
// stop
@@ -165,6 +169,64 @@
method: "erpnext.stock.doctype.material_request.material_request.make_stock_entry",
frm: cur_frm
});
+ },
+
+
+ make_production_order: function() {
+ var items = []
+ $.each(cur_frm.doc["items"] || [], function(i, d) {
+ items.push(d.item_code);
+ });
+ var d = new frappe.ui.Dialog({
+ title: __("Production Order"),
+ fields: [
+ {
+ "fieldtype": "Link",
+ "label": __("Production Item"),
+ "fieldname": "item",
+ "options": "Item",
+ "reqd": 1,
+ "get_query": function() {
+ return {
+ "filters": [
+ ['item_code', 'in', items],
+ ]
+ }
+ }
+ }
+ ]
+
+ });
+
+ d.set_primary_action(__("Make"), function() {
+ frappe.call({
+ method:"erpnext.stock.doctype.material_request.material_request.validate_production_item",
+ args: {
+ "item_code": d.get_values().item
+ },
+ callback: function(r) {
+ if(!r.message) {
+ msgprint("Cannot create Production Order for selected Item.")
+ }
+ else {
+ frappe.call({
+ method:"erpnext.stock.doctype.material_request.material_request.make_production_order",
+ args: {
+ "source_name": cur_frm.doc.name,
+ "item_code": d.get_values().item,
+ },
+ callback: function(r) {
+ if(!r.exe) {
+ var doclist = frappe.model.sync(r.message);
+ frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
+ }
+ }
+ });
+ }
+ }
+ });
+ });
+ d.show();
}
});
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index bd1f4d9..2fcf91d 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -327,3 +327,23 @@
}, target_doc, set_missing_values)
return doclist
+
+
+@frappe.whitelist()
+def validate_production_item(item_code):
+ return frappe.db.get_value("Item", item_code, "is_pro_applicable")
+
+@frappe.whitelist()
+def make_production_order(source_name, item_code):
+ material_request= frappe.get_doc("Material Request", source_name)
+ prod_order = frappe.new_doc("Production Order")
+ prod_order.production_item = item_code
+ prod_order.qty = 0
+ for d in material_request.items:
+ if d.item_code == item_code:
+ prod_order.qty = d.qty - d.ordered_qty
+ prod_order.fg_warehouse = d.warehouse
+ prod_order.expected_delivery_date = d.schedule_date
+ prod_order.sales_order = d.sales_order_no
+ prod_order.material_request = material_request.name
+ return prod_order