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 f41c6dae41..40e62f1c93 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -8,7 +8,7 @@ frappe.require("assets/erpnext/js/utils.js"); frappe.ui.form.on("Request for Quotation",{ setup: function(frm){ - frm.fields_dict["suppliers"].grid.get_field("contact_person").get_query = function(doc, cdt, cdn){ + frm.fields_dict["suppliers"].grid.get_field("contact").get_query = function(doc, cdt, cdn){ var d =locals[cdt][cdn]; return { filters: {'supplier': d.supplier} @@ -18,11 +18,25 @@ frappe.ui.form.on("Request for Quotation",{ onload: function(frm){ frm.add_fetch('standard_reply', 'response', 'response'); + + if(!frm.doc.message_for_supplier) { + frm.set_value("message_for_supplier", __("Please supply the specified items at the best possible rates")) + } }, - + refresh: function(frm, cdt, cdn){ if (frm.doc.docstatus === 1) { - frm.add_custom_button(__("Make Supplier Quotation"), function(){ frm.trigger("make_suppplier_quotation") }); + frm.add_custom_button(__("Make Supplier Quotation"), + function(){ frm.trigger("make_suppplier_quotation") }); + + frm.add_custom_button(__("Send Supplier Emails"), function() { + frappe.call({ + method: 'erpnext.buying.doctype.request_for_quotation.request_for_quotation.send_supplier_emails', + args: { + rfq_name: frm.doc.name + } + }); + }); } }, @@ -31,13 +45,16 @@ frappe.ui.form.on("Request for Quotation",{ var dialog = new frappe.ui.Dialog({ title: __("For Supplier"), fields: [ - {"fieldtype": "Select", "label": __("Supplier"), "fieldname": "supplier", "options":"Supplier", - "options": $.map(doc.suppliers, function(d){ return d.supplier }), "reqd": 1 }, - {"fieldtype": "Button", "label": __("Make Supplier Quotation"), "fieldname": "make_supplier_quotation", "cssClass": "btn-primary"}, + {"fieldtype": "Select", "label": __("Supplier"), + "fieldname": "supplier", "options":"Supplier", + "options": $.map(doc.suppliers, + function(d) { return d.supplier }), "reqd": 1 }, + {"fieldtype": "Button", "label": __("Make Supplier Quotation"), + "fieldname": "make_supplier_quotation", "cssClass": "btn-primary"}, ] }); - dialog.fields_dict.make_supplier_quotation.$input.click(function(){ + dialog.fields_dict.make_supplier_quotation.$input.click(function() { args = dialog.get_values(); if(!args) return; dialog.hide(); diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json index 88a91a0a37..7f1988a8b5 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json @@ -159,7 +159,7 @@ "label": "Supplier Detail", "length": 0, "no_copy": 0, - "options": "RFQ Supplier", + "options": "Request for Quotation Supplier", "permlevel": 0, "precision": "", "print_hide": 1, @@ -281,7 +281,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "response", + "fieldname": "message_for_supplier", "fieldtype": "Text Editor", "hidden": 0, "ignore_user_permissions": 0, @@ -609,7 +609,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-03-25 01:14:01.194848", + "modified": "2016-03-29 06:18:26.398938", "modified_by": "Administrator", "module": "Buying", "name": "Request for Quotation", @@ -763,5 +763,6 @@ "sort_field": "modified", "sort_order": "DESC", "timeline_field": "", - "title_field": "" + "title_field": "", + "track_seen": 0 } \ No newline at end of file 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 92089e4a16..8c23f96074 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe, json from frappe import _ -from frappe.utils import get_url, cint +from frappe.utils import get_url, random_string from frappe.utils.user import get_user_fullname from frappe.model.mapper import get_mapped_doc from erpnext.stock.doctype.material_request.material_request import set_missing_values @@ -29,44 +29,55 @@ class RequestforQuotation(BuyingController): def on_submit(self): frappe.db.set(self, 'status', 'Submitted') - self.send_to_supplier() def on_cancel(self): frappe.db.set(self, 'status', 'Cancelled') def send_to_supplier(self): link = get_url("/rfq/" + self.name) - for supplier_data in self.suppliers: - if supplier_data.email_id and cint(supplier_data.sent_email_to_supplier)==1: - update_password_link = self.create_supplier_user(supplier_data, link) - self.supplier_rfq_mail(supplier_data, update_password_link, link) + for rfq_supplier in self.suppliers: + if rfq_supplier.email_id and rfq_supplier.send_email_to_supplier: - def create_supplier_user(self, supplier_data, link): - from frappe.utils import random_string, get_url + # make new user if required + update_password_link = self.create_supplier_user(rfq_supplier, link) + self.supplier_rfq_mail(rfq_supplier, update_password_link, link) + + def create_supplier_user(self, rfq_supplier, link): + '''Create a new user for the supplier if not set in contact''' update_password_link = '' - if not supplier_data.user_id: - user = self.create_user(supplier_data) - key = random_string(32) - user.reset_password_key = key - user.redirect_url = link - user.save(ignore_permissions=True) - update_password_link = get_url("/update-password?key=" + key) - frappe.get_doc('Contact', supplier_data.contact_person).save() + contact = frappe.get_doc("Contact", rfq_supplier.contact) + if not contact.user: + if frappe.db.exists("User", rfq_supplier.email_id): + user = frappe.get_doc("User", rfq_supplier.email_id) + else: + user, update_password_link = self.create_user(rfq_supplier, link) + + # set user_id in contact + contact = frappe.get_doc('Contact', rfq_supplier.contact) + contact.user = user.name + contact.save() return update_password_link - def create_user(self, supplier_data): + def create_user(self, rfq_supplier, link): user = frappe.get_doc({ 'doctype': 'User', 'send_welcome_email': 0, - 'email': supplier_data.email_id, - 'first_name': supplier_data.supplier_name, + 'email': rfq_supplier.email_id, + 'first_name': rfq_supplier.supplier_name, 'user_type': 'Website User' }) - return user + # reset password + key = random_string(32) + update_password_link = get_url("/update-password?key=" + key) + user.reset_password_key = key + user.redirect_url = link + user.save(ignore_permissions=True) + + return user, update_password_link def supplier_rfq_mail(self, data, update_password_link, rfq_link): full_name = get_user_fullname(frappe.session['user']) @@ -75,7 +86,7 @@ class RequestforQuotation(BuyingController): args = { 'update_password_link': update_password_link, - 'message': frappe.render_template(self.response, data.as_dict()), + 'message': frappe.render_template(self.message_for_supplier, data.as_dict()), 'rfq_link': rfq_link, 'user_fullname': full_name } @@ -90,18 +101,18 @@ class RequestforQuotation(BuyingController): frappe.msgprint(_("Email sent to supplier {0}").format(data.supplier)) +@frappe.whitelist() +def send_supplier_emails(rfq_name): + rfq = frappe.get_doc("Request for Quotation", rfq_name) + if rfq.docstatus==1: + rfq.send_to_supplier() + + def get_list_context(context=None): from erpnext.controllers.website_list_for_contact import get_list_context list_context = get_list_context(context) return list_context -@frappe.whitelist() -def get_supplier(doctype, txt, searchfield, start, page_len, filters): - query = """Select supplier from `tabRFQ Supplier` where parent = %(parent)s and supplier like %(txt)s - limit %(start)s, %(page_len)s """ - - return frappe.db.sql(query, {'parent': filters.get('parent'), - 'start': start, 'page_len': page_len, 'txt': "%%%s%%" % frappe.db.escape(txt)}) # This method is used to make supplier quotation from material request form. @frappe.whitelist() @@ -160,7 +171,7 @@ def add_items(sq_doc, supplier, items): if data.get("qty") > 0: if isinstance(data, dict): data = frappe._dict(data) - + create_rfq_items(sq_doc, supplier, data) def create_rfq_items(sq_doc, supplier, data): diff --git a/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json b/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json index 305253c193..2892e3bf41 100644 --- a/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json +++ b/erpnext/buying/doctype/request_for_quotation_item/request_for_quotation_item.json @@ -299,6 +299,7 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "default": "Today", "fieldname": "schedule_date", "fieldtype": "Date", "hidden": 0, @@ -598,7 +599,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-03-25 01:14:38.490488", + "modified": "2016-03-29 05:28:39.203232", "modified_by": "Administrator", "module": "Buying", "name": "Request for Quotation Item", @@ -608,5 +609,6 @@ "read_only": 0, "read_only_onload": 0, "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/buying/doctype/rfq_supplier/__init__.py b/erpnext/buying/doctype/request_for_quotation_supplier/__init__.py similarity index 100% rename from erpnext/buying/doctype/rfq_supplier/__init__.py rename to erpnext/buying/doctype/request_for_quotation_supplier/__init__.py diff --git a/erpnext/buying/doctype/rfq_supplier/rfq_supplier.json b/erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.json similarity index 79% rename from erpnext/buying/doctype/rfq_supplier/rfq_supplier.json rename to erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.json index 02a6f0ba33..b51bc17e82 100644 --- a/erpnext/buying/doctype/rfq_supplier/rfq_supplier.json +++ b/erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.json @@ -2,7 +2,7 @@ "allow_copy": 0, "allow_import": 0, "allow_rename": 0, - "creation": "2016-02-29 17:31:02.993221", + "creation": "2016-03-29 05:59:11.896885", "custom": 0, "docstatus": 0, "doctype": "DocType", @@ -38,14 +38,14 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "contact_person", + "fieldname": "contact", "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 1, - "label": "Contact Person", + "label": "Contact", "length": 0, "no_copy": 1, "options": "Contact", @@ -65,15 +65,15 @@ "bold": 0, "collapsible": 0, "default": "1", - "description": "Send Request for Quotation to Supplier", - "fieldname": "sent_email_to_supplier", + "description": "", + "fieldname": "send_email_to_supplier", "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_list_view": 0, - "label": "Sent Email to Supplier", + "label": "Send Email to Supplier", "length": 0, "no_copy": 1, "permlevel": 0, @@ -151,7 +151,7 @@ "label": "Email Id", "length": 0, "no_copy": 1, - "options": "contact_person.email_id", + "options": "contact.email_id", "permlevel": 0, "precision": "", "print_hide": 0, @@ -162,32 +162,6 @@ "search_index": 0, "set_only_once": 0, "unique": 0 - }, - { - "allow_on_submit": 1, - "bold": 0, - "collapsible": 0, - "fieldname": "user_id", - "fieldtype": "Read Only", - "hidden": 1, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "User Id", - "length": 0, - "no_copy": 1, - "options": "contact_person.user", - "permlevel": 0, - "precision": "", - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 } ], "hide_heading": 0, @@ -199,15 +173,16 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-03-25 13:18:11.017660", + "modified": "2016-03-29 06:03:50.811469", "modified_by": "Administrator", "module": "Buying", - "name": "RFQ Supplier", + "name": "Request for Quotation Supplier", "name_case": "", "owner": "Administrator", "permissions": [], "read_only": 0, "read_only_onload": 0, "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/buying/doctype/rfq_supplier/rfq_supplier.py b/erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.py similarity index 84% rename from erpnext/buying/doctype/rfq_supplier/rfq_supplier.py rename to erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.py index a7ba65c673..4b0bbbee8c 100644 --- a/erpnext/buying/doctype/rfq_supplier/rfq_supplier.py +++ b/erpnext/buying/doctype/request_for_quotation_supplier/request_for_quotation_supplier.py @@ -6,5 +6,5 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -class RFQSupplier(Document): +class RequestforQuotationSupplier(Document): pass diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index 588257828f..7b934e71a5 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -28,7 +28,7 @@ def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_p filters.append((doctype, "docstatus", "=", 1)) if user != "Guest" and is_website_user(): - parties_doctype = 'RFQ Supplier' if doctype == 'Request for Quotation' else doctype + parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype # find party for this contact customers, suppliers = get_customers_suppliers(parties_doctype, user) key, parties = get_party_details(customers, suppliers) diff --git a/erpnext/templates/emails/request_for_quotation.html b/erpnext/templates/emails/request_for_quotation.html index 91bdd6b782..aedd8e2079 100644 --- a/erpnext/templates/emails/request_for_quotation.html +++ b/erpnext/templates/emails/request_for_quotation.html @@ -1,12 +1,11 @@
{{ message }}
{% if update_password_link %}{{_("Please click on the following link to set your new password")}}:
{% else %}{{_("Request for quotation can be access by clicking following link")}}:
- + {% endif %}{{_("Thank you")}},
{{ user_fullname }}
{{ _("Notes: ") }}
+