From 1cd7e54822a4a4f2ec3aa6729de3c94a38471500 Mon Sep 17 00:00:00 2001 From: Ben Cornwell-Mott Date: Wed, 11 Jan 2017 03:05:49 -0800 Subject: [PATCH 1/2] Adds button to find MRs linked to Supplier --- .../request_for_quotation.js | 40 +++++++++++++++++ .../request_for_quotation.py | 43 ++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) 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 6847a98aa19..2822733a8fc 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 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e } }) }, __("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 3ff45f55d43..95925347b83 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.utils.print_format import download_pdf 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 @@ def get_rfq_doc(doctype, name, supplier_idx): 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 From 2ad62c289248dd3c0ec0b982afab22f42e4161a2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 17 Jan 2017 12:25:33 +0530 Subject: [PATCH 2/2] In RFQ, get items from material requests based on possible supplier --- .../request_for_quotation.js | 18 ++--- .../request_for_quotation.py | 79 ++++++++++--------- 2 files changed, 49 insertions(+), 48 deletions(-) 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 2822733a8fc..113dbe00fef 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -134,21 +134,19 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e } }) }, __("Get items from")); - cur_frm.add_custom_button(__('Possible Supplier'), - function() { - - - - //Create a dialog window for the user to pick their supplier + + // Get items from open Material Requests based on supplier + 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'}, + {fieldname: 'ok_button', fieldtype:'Button', label:'Get Items from Material Requests'}, ] }); - //On the user clicking the ok button + // 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(); @@ -156,7 +154,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e $(btn).set_working(); erpnext.utils.map_current_doc({ - method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.get_matreq_from_possible_supplier", + method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.get_item_from_material_requests_based_on_supplier", source_name: v.supplier, get_query_filters: { material_request_type: "Purchase", @@ -167,10 +165,8 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e } }); $(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 95925347b83..630086436fa 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -6,13 +6,13 @@ from __future__ import unicode_literals import frappe, json from frappe import _ from frappe.model.mapper import get_mapped_doc -from frappe.utils import get_url, random_string, cint +from frappe.utils import get_url, cint from frappe.utils.user import get_user_fullname from frappe.utils.print_format import download_pdf 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, make_request_for_quotation +from erpnext.stock.doctype.material_request.material_request import set_missing_values from erpnext.controllers.buying_controller import BuyingController STANDARD_USERS = ("Guest", "Administrator") @@ -246,42 +246,47 @@ def get_rfq_doc(doctype, name, supplier_idx): return doc @frappe.whitelist() -def get_matreq_from_possible_supplier(source_name, target_doc = None): +def get_item_from_material_requests_based_on_supplier(source_name, target_doc = None): + mr_items_list = frappe.db.sql(""" + SELECT + mr.name, mr_item.item_code + FROM + `tabItem` as item, + `tabItem Supplier` as item_supp, + `tabMaterial Request Item` as mr_item, + `tabMaterial Request` as mr + WHERE item_supp.supplier = %(supplier)s + AND item.name = item_supp.parent + AND mr_item.parent = mr.name + AND mr_item.item_code = item.name + AND mr.status != "Stopped" + AND mr.material_request_type = "Purchase" + AND mr.docstatus = 1 + AND mr.per_ordered < 99.99""", {"supplier": source_name}, as_dict=1) + + material_requests = {} + for d in mr_items_list: + material_requests.setdefault(d.name, []).append(d.item_code) - 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"], - + for mr, items in material_requests.items(): + target_doc = get_mapped_doc("Material Request", mr, { + "Material Request": { + "doctype": "Request for Quotation", + "validation": { + "docstatus": ["=", 1], + "material_request_type": ["=", "Purchase"], + } + }, + "Material Request Item": { + "doctype": "Request for Quotation Item", + "condition": lambda row: row.item_code in items, + "field_map": [ + ["name", "material_request_item"], + ["parent", "material_request"], + ["uom", "uom"] + ] } - }, - "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) + }, target_doc) + return target_doc \ No newline at end of file