[fix] contact us page should create a opportunity by default (#6939)
This commit is contained in:
parent
b3ba7f01ef
commit
d51e1587d5
@ -10,15 +10,43 @@ from frappe.utils import cint, formatdate
|
|||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def send_message(subject="Website Query", message="", sender="", status="Open"):
|
def send_message(subject="Website Query", message="", sender="", status="Open"):
|
||||||
from frappe.www.contact import send_message as website_send_message
|
from frappe.www.contact import send_message as website_send_message
|
||||||
|
lead = customer = None
|
||||||
|
|
||||||
website_send_message(subject, message, sender)
|
website_send_message(subject, message, sender)
|
||||||
|
|
||||||
|
customer = frappe.db.get_value('Contact', dict(email_id=sender), 'customer')
|
||||||
|
if not customer:
|
||||||
|
lead = frappe.db.get_value('Lead', dict(email_id=sender))
|
||||||
|
if not lead:
|
||||||
|
new_lead = frappe.get_doc(dict(
|
||||||
|
doctype='Lead',
|
||||||
|
email_id = sender,
|
||||||
|
lead_name = sender.split('@')[0].title()
|
||||||
|
)).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
opportunity = frappe.get_doc(dict(
|
||||||
|
doctype='Opportunity',
|
||||||
|
enquiry_from = 'Customer' if customer else 'Lead',
|
||||||
|
status = 'Open',
|
||||||
|
title = subject,
|
||||||
|
to_discuss=message
|
||||||
|
))
|
||||||
|
|
||||||
|
if customer:
|
||||||
|
opportunity.customer = customer
|
||||||
|
else:
|
||||||
|
opportunity.lead = new_lead.name
|
||||||
|
|
||||||
|
opportunity.insert(ignore_permissions=True)
|
||||||
|
|
||||||
comm = frappe.get_doc({
|
comm = frappe.get_doc({
|
||||||
"doctype":"Communication",
|
"doctype":"Communication",
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"content": message,
|
"content": message,
|
||||||
"sender": sender,
|
"sender": sender,
|
||||||
"sent_or_received": "Received"
|
"sent_or_received": "Received",
|
||||||
|
'reference_doctype': 'Opportunity',
|
||||||
|
'reference_name': opportunity.name
|
||||||
})
|
})
|
||||||
comm.insert(ignore_permissions=True)
|
comm.insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user