From f154c611bb721401081dd839d717e152420abd52 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 6 Jul 2016 17:26:15 +0530 Subject: [PATCH] [Fixes] RFQ contact and multiple creation of supplier quotation issue --- .../request_for_quotation.js | 15 +++++++++++++-- .../request_for_quotation.py | 14 +++++++++++++- erpnext/templates/includes/rfq.js | 1 + 3 files changed, 27 insertions(+), 3 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 6058cb4d1b..e526034b07 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -100,8 +100,19 @@ frappe.ui.form.on("Request for Quotation",{ frappe.ui.form.on("Request for Quotation Supplier",{ supplier: function(frm, cdt, cdn) { var d = locals[cdt][cdn] - frappe.model.set_value(cdt, cdn, 'contact', '') - frappe.model.set_value(cdt, cdn, 'email_id', '') + frappe.call({ + method:"erpnext.accounts.party.get_party_details", + args:{ + party: d.supplier, + party_type: 'Supplier' + }, + callback: function(r){ + if(r.message){ + frappe.model.set_value(cdt, cdn, 'contact', r.message.contact_person) + frappe.model.set_value(cdt, cdn, 'email_id', r.message.contact_email) + } + } + }) }, download_pdf: function(frm, cdt, cdn) { 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 eea796ad31..b01d3e844b 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -192,6 +192,8 @@ def create_supplier_quotation(doc): if isinstance(doc, basestring): doc = json.loads(doc) + validate_duplicate_supplier_quotation(doc) + try: sq_doc = frappe.get_doc({ "doctype": "Supplier Quotation", @@ -242,4 +244,14 @@ def get_rfq_doc(doctype, name, supplier_idx): doc = frappe.get_doc(doctype, name) args = doc.get('suppliers')[cint(supplier_idx) - 1] doc.update_supplier_part_no(args) - return doc \ No newline at end of file + return doc + +@frappe.whitelist() +def validate_duplicate_supplier_quotation(args): + data = frappe.db.sql("""select sq.name as name from `tabSupplier Quotation` sq, + `tabSupplier Quotation Item` sqi where sqi.parent = sq.name and sq.supplier = %(supplier)s + and sqi.request_for_quotation = %(rfq)s and sq.docstatus < 2""", + {'supplier': args.get('supplier'), 'rfq': args.get('name')}, as_dict=True) + + if data and data[0] and data[0].name: + frappe.throw(_("Already supplier quotation has created")) diff --git a/erpnext/templates/includes/rfq.js b/erpnext/templates/includes/rfq.js index ea003d84fa..3e9c261a20 100644 --- a/erpnext/templates/includes/rfq.js +++ b/erpnext/templates/includes/rfq.js @@ -79,6 +79,7 @@ rfq = Class.extend({ }, btn: this, callback: function(r){ + $('.btn-sm').hide() frappe.unfreeze(); } })