[RFQ] Enhancement and minor fixes
This commit is contained in:
parent
65256ed8cb
commit
a314872cb5
@ -4,7 +4,7 @@
|
||||
|
||||
{% include 'erpnext/buying/doctype/purchase_common/purchase_common.js' %};
|
||||
|
||||
|
||||
cur_frm.add_fetch('contact', 'email_id', 'email_id')
|
||||
|
||||
frappe.ui.form.on("Request for Quotation",{
|
||||
setup: function(frm){
|
||||
@ -23,7 +23,7 @@ frappe.ui.form.on("Request for Quotation",{
|
||||
];
|
||||
|
||||
frm.get_field('suppliers').grid.editable_fields = [
|
||||
{fieldname: 'supplier', columns: 5},
|
||||
{fieldname: 'supplier', columns: 4},
|
||||
{fieldname: 'contact', columns: 3},
|
||||
{fieldname: 'email_id', columns: 3}
|
||||
];
|
||||
|
@ -3,6 +3,7 @@
|
||||
"allow_import": 1,
|
||||
"allow_rename": 0,
|
||||
"autoname": "naming_series:",
|
||||
"beta": 0,
|
||||
"creation": "2016-02-25 01:24:07.224790",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
@ -66,6 +67,33 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "For individual supplier",
|
||||
"fieldname": "vendor",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Supplier",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Supplier",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -603,13 +631,14 @@
|
||||
"hide_toolbar": 0,
|
||||
"icon": "icon-shopping-cart",
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 1,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-03-29 06:18:26.398938",
|
||||
"modified": "2016-06-30 01:57:49.233065",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation",
|
||||
@ -757,6 +786,7 @@
|
||||
"write": 0
|
||||
}
|
||||
],
|
||||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 1,
|
||||
"search_fields": "status, transaction_date",
|
||||
|
@ -8,6 +8,8 @@ from frappe import _
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.utils import get_url, random_string
|
||||
from frappe.utils.user import get_user_fullname
|
||||
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.controllers.buying_controller import BuyingController
|
||||
@ -34,6 +36,10 @@ class RequestforQuotation(BuyingController):
|
||||
if not rfq_supplier.email_id:
|
||||
rfq_supplier.email_id = frappe.db.get_value("Contact", rfq_supplier.contact, "email_id")
|
||||
|
||||
def validate_email_id(self, args):
|
||||
if not args.email_id:
|
||||
frappe.throw(_("Row {0}: For supplier {0} email id is required to send email").format(args.idx, args.supplier))
|
||||
|
||||
def on_submit(self):
|
||||
frappe.db.set(self, 'status', 'Submitted')
|
||||
|
||||
@ -41,42 +47,61 @@ class RequestforQuotation(BuyingController):
|
||||
frappe.db.set(self, 'status', 'Cancelled')
|
||||
|
||||
def send_to_supplier(self):
|
||||
link = get_url("/rfq/" + self.name)
|
||||
for rfq_supplier in self.suppliers:
|
||||
if rfq_supplier.email_id:
|
||||
if rfq_supplier.send_email:
|
||||
self.validate_email_id(rfq_supplier)
|
||||
|
||||
# make new user if required
|
||||
update_password_link = self.create_supplier_user(rfq_supplier, link)
|
||||
update_password_link = self.update_supplier_contact(rfq_supplier, self.get_link())
|
||||
|
||||
self.supplier_rfq_mail(rfq_supplier, update_password_link, link)
|
||||
else:
|
||||
frappe.throw(_("For supplier {0} email id is required to send email").format(rfq_supplier.supplier))
|
||||
self.update_supplier_part_no(rfq_supplier)
|
||||
self.supplier_rfq_mail(rfq_supplier, update_password_link, self.get_link())
|
||||
|
||||
def create_supplier_user(self, rfq_supplier, link):
|
||||
def get_link(self):
|
||||
# RFQ link for supplier portal
|
||||
return get_url("/rfq/" + self.name)
|
||||
|
||||
def update_supplier_part_no(self, args):
|
||||
self.vendor = args.supplier
|
||||
for item in self.items:
|
||||
item.supplier_part_no = frappe.db.get_value('Item Supplier',
|
||||
{'parent': item.item_code, 'supplier': args.supplier}, 'supplier_part_no')
|
||||
|
||||
def update_supplier_contact(self, rfq_supplier, link):
|
||||
'''Create a new user for the supplier if not set in contact'''
|
||||
update_password_link = ''
|
||||
|
||||
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)
|
||||
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()
|
||||
self.update_contact_of_supplier(rfq_supplier, user)
|
||||
|
||||
return update_password_link
|
||||
|
||||
def update_contact_of_supplier(self, rfq_supplier, user):
|
||||
if rfq_supplier.contact:
|
||||
contact = frappe.get_doc("Contact", rfq_supplier.contact)
|
||||
else:
|
||||
contact = frappe.new_doc("Contact")
|
||||
contact.first_name = rfq_supplier.supplier_name or rfq_supplier.supplier
|
||||
contact.supplier = rfq_supplier.supplier
|
||||
|
||||
if not contact.email_id and not contact.user:
|
||||
contact.email_id = user.name
|
||||
contact.user = user.name
|
||||
|
||||
contact.save(ignore_permissions=True)
|
||||
|
||||
def create_user(self, rfq_supplier, link):
|
||||
user = frappe.get_doc({
|
||||
'doctype': 'User',
|
||||
'send_welcome_email': 0,
|
||||
'email': rfq_supplier.email_id,
|
||||
'first_name': rfq_supplier.supplier_name,
|
||||
'user_type': 'Website User'
|
||||
'first_name': rfq_supplier.supplier_name or rfq_supplier.supplier,
|
||||
'user_type': 'Website User',
|
||||
'redirect_url': link
|
||||
})
|
||||
user.save(ignore_permissions=True)
|
||||
update_password_link = user.reset_password()
|
||||
@ -98,12 +123,22 @@ class RequestforQuotation(BuyingController):
|
||||
subject = _("Request for Quotation")
|
||||
template = "templates/emails/request_for_quotation.html"
|
||||
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
|
||||
message = frappe.get_template(template).render(args)
|
||||
attachments = self.get_attachments()
|
||||
|
||||
self.send_email(data, sender, subject, message, attachments)
|
||||
|
||||
def send_email(self, data, sender, subject, message, attachments):
|
||||
make(subject = subject, content=message,recipients=data.email_id,
|
||||
sender=sender,attachments = attachments, send_email=True)["name"]
|
||||
|
||||
frappe.sendmail(recipients=data.email_id, sender=sender, subject=subject,
|
||||
message=frappe.get_template(template).render(args),
|
||||
attachments = [frappe.attach_print('Request for Quotation', self.name)])
|
||||
frappe.msgprint(_("Email sent to supplier {0}").format(data.supplier))
|
||||
|
||||
def get_attachments(self):
|
||||
attachments = [d.name for d in get_attachments(self.doctype, self.name)]
|
||||
attachments.append(frappe.attach_print('Request for Quotation', self.name, doc=self))
|
||||
return attachments
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_supplier_emails(rfq_name):
|
||||
rfq = frappe.get_doc("Request for Quotation", rfq_name)
|
||||
|
@ -38,6 +38,31 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "supplier_part_no",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Supplier Part No",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -601,8 +626,8 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-06-17 12:25:37.655901",
|
||||
"modified_by": "umair@erpnext.com",
|
||||
"modified": "2016-06-28 14:25:08.330508",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation Item",
|
||||
"name_case": "",
|
||||
|
@ -9,6 +9,32 @@
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"default": "1",
|
||||
"fieldname": "send_email",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Send Email",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -141,13 +167,14 @@
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-05-31 19:08:15.397706",
|
||||
"modified": "2016-06-30 02:01:54.130809",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation Supplier",
|
||||
|
Loading…
Reference in New Issue
Block a user