2015-03-03 14:55:30 +05:30
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-09-10 13:46:15 +05:30
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-10-21 16:16:30 +05:30
|
|
|
|
|
|
|
import frappe, json
|
|
|
|
from frappe import _
|
|
|
|
from frappe.utils import cint, formatdate
|
2013-09-11 18:58:20 +05:30
|
|
|
|
2014-02-14 15:47:51 +05:30
|
|
|
@frappe.whitelist(allow_guest=True)
|
2013-09-11 18:58:20 +05:30
|
|
|
def send_message(subject="Website Query", message="", sender="", status="Open"):
|
2016-06-23 18:25:50 +05:30
|
|
|
from frappe.www.contact import send_message as website_send_message
|
2016-11-16 11:13:31 +05:30
|
|
|
lead = customer = None
|
2014-04-18 16:15:31 +05:30
|
|
|
|
2014-09-15 16:59:38 +05:30
|
|
|
website_send_message(subject, message, sender)
|
2014-04-18 16:15:31 +05:30
|
|
|
|
2016-11-16 11:13:31 +05:30
|
|
|
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)
|
|
|
|
|
2014-09-15 16:59:38 +05:30
|
|
|
comm = frappe.get_doc({
|
|
|
|
"doctype":"Communication",
|
|
|
|
"subject": subject,
|
|
|
|
"content": message,
|
|
|
|
"sender": sender,
|
2016-11-16 11:13:31 +05:30
|
|
|
"sent_or_received": "Received",
|
|
|
|
'reference_doctype': 'Opportunity',
|
|
|
|
'reference_name': opportunity.name
|
2014-09-15 16:59:38 +05:30
|
|
|
})
|
|
|
|
comm.insert(ignore_permissions=True)
|
2015-08-25 14:03:43 +05:30
|
|
|
|
|
|
|
return "okay"
|