Merge pull request #7671 from bcornwellmott/link_mrs
Created button to link buying items to material requests
This commit is contained in:
commit
8312f1cd64
@ -221,6 +221,67 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
|
|
||||||
tc_name: function() {
|
tc_name: function() {
|
||||||
this.get_terms();
|
this.get_terms();
|
||||||
|
},
|
||||||
|
link_to_mrs: function() {
|
||||||
|
my_items = [];
|
||||||
|
for (var i in cur_frm.doc.items) {
|
||||||
|
if(!cur_frm.doc.items[i].material_request){
|
||||||
|
my_items.push(cur_frm.doc.items[i].item_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.buying.doctype.purchase_common.purchase_common.get_linked_material_requests",
|
||||||
|
args:{
|
||||||
|
items: my_items
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
var i = 0;
|
||||||
|
var item_length = cur_frm.doc.items.length;
|
||||||
|
while (i < item_length) {
|
||||||
|
var qty = cur_frm.doc.items[i].qty;
|
||||||
|
(r.message[0] || []).forEach(function(d) {
|
||||||
|
if (d.qty > 0 && qty > 0 && cur_frm.doc.items[i].item_code == d.item_code && !cur_frm.doc.items[i].material_request_item)
|
||||||
|
{
|
||||||
|
cur_frm.doc.items[i].material_request = d.mr_name;
|
||||||
|
cur_frm.doc.items[i].material_request_item = d.mr_item;
|
||||||
|
my_qty = Math.min(qty, d.qty);
|
||||||
|
qty = qty - my_qty;
|
||||||
|
d.qty = d.qty - my_qty;
|
||||||
|
cur_frm.doc.items[i].stock_qty = my_qty*cur_frm.doc.items[i].conversion_factor;
|
||||||
|
cur_frm.doc.items[i].qty = my_qty;
|
||||||
|
|
||||||
|
frappe.msgprint("Assigning " + d.mr_name + " to " + d.item_code + " (row " + cur_frm.doc.items[i].idx + ")");
|
||||||
|
if (qty > 0)
|
||||||
|
{
|
||||||
|
frappe.msgprint("Splitting " + qty + " units of " + d.item_code);
|
||||||
|
var newrow = frappe.model.add_child(cur_frm.doc, cur_frm.doc.items[i].doctype, "items");
|
||||||
|
item_length++;
|
||||||
|
|
||||||
|
for (key in cur_frm.doc.items[i])
|
||||||
|
{
|
||||||
|
newrow[key] = cur_frm.doc.items[i][key];
|
||||||
|
}
|
||||||
|
|
||||||
|
newrow.idx = item_length;
|
||||||
|
newrow["stock_qty"] = newrow.conversion_factor*qty;
|
||||||
|
newrow["qty"] = qty;
|
||||||
|
|
||||||
|
newrow["material_request"] = "";
|
||||||
|
newrow["material_request_item"] = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
refresh_field("items");
|
||||||
|
//cur_frm.save();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe, json
|
||||||
from frappe.utils import flt, cstr, cint
|
from frappe.utils import flt, cstr, cint
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
@ -79,3 +79,27 @@ class PurchaseCommon(BuyingController):
|
|||||||
|
|
||||||
if status == "Closed":
|
if status == "Closed":
|
||||||
frappe.throw(_("{0} {1} status is {2}").format(doctype, docname, status), frappe.InvalidStatusError)
|
frappe.throw(_("{0} {1} status is {2}").format(doctype, docname, status), frappe.InvalidStatusError)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_linked_material_requests(items):
|
||||||
|
items = json.loads(items)
|
||||||
|
mr_list = []
|
||||||
|
for item in items:
|
||||||
|
material_request = frappe.db.sql("""SELECT distinct mr.name AS mr_name,
|
||||||
|
(mr_item.qty - mr_item.ordered_qty) AS qty,
|
||||||
|
mr_item.item_code AS item_code,
|
||||||
|
mr_item.name AS mr_item
|
||||||
|
FROM `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
|
||||||
|
WHERE mr.name = mr_item.parent
|
||||||
|
AND mr_item.item_code = %(item)s
|
||||||
|
AND mr.material_request_type = 'Purchase'
|
||||||
|
AND mr.per_ordered < 99.99
|
||||||
|
AND mr.docstatus = 1
|
||||||
|
AND mr.status != 'Stopped'
|
||||||
|
ORDER BY mr_item.item_code ASC""",{"item": item}, as_dict=1)
|
||||||
|
if material_request:
|
||||||
|
mr_list.append(material_request)
|
||||||
|
|
||||||
|
return mr_list
|
||||||
|
|
||||||
|
|
@ -1196,6 +1196,34 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)",
|
||||||
|
"fieldname": "link_to_mrs",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Link to material requests",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -3168,7 +3196,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2017-02-22 18:20:15.650815",
|
"modified": "2017-02-28 18:20:15.650815",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order",
|
"name": "Purchase Order",
|
||||||
|
@ -47,6 +47,7 @@ frappe.ui.form.on("Request for Quotation",{
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
make_suppplier_quotation: function(frm) {
|
make_suppplier_quotation: function(frm) {
|
||||||
@ -138,7 +139,6 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, __("Get items from"));
|
}, __("Get items from"));
|
||||||
|
|
||||||
// Get items from open Material Requests based on supplier
|
// Get items from open Material Requests based on supplier
|
||||||
cur_frm.add_custom_button(__('Possible Supplier'), function() {
|
cur_frm.add_custom_button(__('Possible Supplier'), function() {
|
||||||
// Create a dialog window for the user to pick their supplier
|
// Create a dialog window for the user to pick their supplier
|
||||||
@ -174,6 +174,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
|
|||||||
}
|
}
|
||||||
d.show();
|
d.show();
|
||||||
}, __("Get items from"));
|
}, __("Get items from"));
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -291,6 +291,34 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)",
|
||||||
|
"fieldname": "link_to_mrs",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Link to material requests",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -731,7 +759,7 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2017-02-17 16:44:39.531065",
|
"modified": "2017-02-28 16:44:39.531065",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Request for Quotation",
|
"name": "Request for Quotation",
|
||||||
|
@ -24,6 +24,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if (this.frm.doc.docstatus===0) {
|
else if (this.frm.doc.docstatus===0) {
|
||||||
|
|
||||||
cur_frm.add_custom_button(__('Material Request'),
|
cur_frm.add_custom_button(__('Material Request'),
|
||||||
function() {
|
function() {
|
||||||
erpnext.utils.map_current_doc({
|
erpnext.utils.map_current_doc({
|
||||||
|
@ -784,6 +784,34 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "eval:doc.docstatus===0 && (doc.items && doc.items.length)",
|
||||||
|
"fieldname": "link_to_mrs",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Link to material requests",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -2115,7 +2143,7 @@
|
|||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"menu_index": 0,
|
"menu_index": 0,
|
||||||
"modified": "2017-02-17 16:45:32.200667",
|
"modified": "2017-02-28 16:45:32.200667",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Supplier Quotation",
|
"name": "Supplier Quotation",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user