Adds button to find MRs linked to Supplier
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 6847a98..2822733 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -134,6 +134,46 @@
}
})
}, __("Get items from"));
+ cur_frm.add_custom_button(__('Possible Supplier'),
+ function() {
+
+
+
+ //Create a dialog window for the user to pick their supplier
+ var d = new frappe.ui.Dialog({
+ title: __('Select Possible Supplier'),
+ fields: [
+ {fieldname: 'supplier', fieldtype:'Link', options:'Supplier', label:'Supplier', reqd:1},
+ {fieldname: 'ok_button', fieldtype:'Button', label:'Get Material Requests'},
+ ]
+ });
+
+ //On the user clicking the ok button
+ d.fields_dict.ok_button.input.onclick = function() {
+ var btn = d.fields_dict.ok_button.input;
+ var v = d.get_values();
+ if(v) {
+ $(btn).set_working();
+
+ erpnext.utils.map_current_doc({
+ method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.get_matreq_from_possible_supplier",
+ source_name: v.supplier,
+ get_query_filters: {
+ material_request_type: "Purchase",
+ docstatus: 1,
+ status: ["!=", "Stopped"],
+ per_ordered: ["<", 99.99],
+ company: cur_frm.doc.company
+ }
+ });
+ $(btn).done_working();
+ //msgprint("Loaded Material Requests");
+ d.hide();
+ }
+
+ }
+ d.show();
+ }, __("Get items from"));
}
},
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
index 3ff45f5..9592534 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -12,7 +12,7 @@
from frappe.desk.form.load import get_attachments
from frappe.core.doctype.communication.email import make
from erpnext.accounts.party import get_party_account_currency, get_party_details
-from erpnext.stock.doctype.material_request.material_request import set_missing_values
+from erpnext.stock.doctype.material_request.material_request import set_missing_values, make_request_for_quotation
from erpnext.controllers.buying_controller import BuyingController
STANDARD_USERS = ("Guest", "Administrator")
@@ -244,3 +244,44 @@
args = doc.get('suppliers')[cint(supplier_idx) - 1]
doc.update_supplier_part_no(args)
return doc
+
+@frappe.whitelist()
+def get_matreq_from_possible_supplier(source_name, target_doc = None):
+
+ item_list = frappe.db.sql("""SELECT matreq.name, matreqi.item_code
+ FROM `tabItem` as item,
+ `tabItem Supplier` as itemsup,
+ `tabMaterial Request Item` as matreqi,
+ `tabMaterial Request` as matreq
+ WHERE itemsup.supplier = %(supplier)s
+ AND item.name = itemsup.parent
+ AND matreqi.parent = matreq.name
+ AND matreqi.item_code = item.name
+ AND matreq.status != "Stopped"
+ AND matreq.material_request_type = "Purchase"
+ AND matreq.docstatus = 1
+ AND matreq.per_ordered < 99.99""", \
+ {"supplier": source_name},as_dict=1)
+ for d in item_list:
+ frappe.msgprint(d.name + " - " + d.item_code)
+ target_doc = get_mapped_doc("Material Request", d.name, {
+ "Material Request": {
+ "doctype": "Request for Quotation",
+ "validation": {
+ "docstatus": ["=", 1],
+ "material_request_type": ["=", "Purchase"],
+
+ }
+ },
+ "Material Request Item": {
+ "doctype": "Request for Quotation Item",
+ "condition": lambda doc: doc.item_code == d.item_code,
+ "field_map": [
+ ["name", "material_request_item"],
+ ["parent", "material_request"],
+ ["uom", "uom"]
+ ]
+ }
+ }, target_doc)
+ return target_doc
+
\ No newline at end of file