mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
added status to Contact and fix bug in communication pull
This commit is contained in:
@@ -20,6 +20,41 @@ from webnotes.utils import cstr, cint
|
||||
from webnotes.utils.email_lib.receive import POP3Mailbox
|
||||
from core.doctype.communication.communication import make
|
||||
|
||||
def add_sales_communication(subject, content, sender, real_name, mail=None):
|
||||
def set_status_open(doctype, name):
|
||||
w = webnotes.model_wrapper(doctype, name)
|
||||
w.ignore_permissions = True
|
||||
w.doc.status = "Open"
|
||||
w.doc.save()
|
||||
if mail:
|
||||
mail.save_attachments_in_doc(w.doc)
|
||||
|
||||
lead_name = webnotes.conn.get_value("Lead", {"email_id": sender})
|
||||
contact_name = webnotes.conn.get_value("Contact", {"email_id": sender})
|
||||
is_system_user = webnotes.conn.get_value("Profile", sender)
|
||||
|
||||
if not is_system_user:
|
||||
if contact_name:
|
||||
set_status_open("Contact", contact_name)
|
||||
elif lead_name:
|
||||
set_status_open("Lead", lead_name)
|
||||
else:
|
||||
# none, create a new Lead
|
||||
lead = webnotes.model_wrapper({
|
||||
"doctype":"Lead",
|
||||
"lead_name": real_name or sender,
|
||||
"email_id": sender,
|
||||
"status": "Open",
|
||||
"source": "Email"
|
||||
})
|
||||
lead.ignore_permissions = True
|
||||
lead.insert()
|
||||
if mail:
|
||||
mail.save_attachments_in_doc(lead.doc)
|
||||
|
||||
make(content=content, sender=sender, subject=subject,
|
||||
lead=lead_name, contact=contact_name)
|
||||
|
||||
class SalesMailbox(POP3Mailbox):
|
||||
def setup(self, args=None):
|
||||
self.settings = args or webnotes.doc("Sales Email Settings", "Sales Email Settings")
|
||||
@@ -31,26 +66,9 @@ class SalesMailbox(POP3Mailbox):
|
||||
def process_message(self, mail):
|
||||
if mail.from_email == self.settings.email_id:
|
||||
return
|
||||
|
||||
name = webnotes.conn.get_value("Lead", {"email_id": mail.from_email}, "name")
|
||||
if name:
|
||||
lead = webnotes.model_wrapper("Lead", name)
|
||||
lead.doc.status = "Open"
|
||||
lead.doc.save()
|
||||
else:
|
||||
lead = webnotes.model_wrapper({
|
||||
"doctype":"Lead",
|
||||
"lead_name": mail.from_real_name or mail.from_email,
|
||||
"email_id": mail.from_email,
|
||||
"status": "Open",
|
||||
"source": "Email"
|
||||
})
|
||||
lead.insert()
|
||||
|
||||
mail.save_attachments_in_doc(lead.doc)
|
||||
|
||||
make(content=mail.content, sender=mail.from_email,
|
||||
doctype="Lead", name=lead.doc.name, lead=lead.doc.name)
|
||||
add_sales_communication(mail.subject, mail.content, mail.form_email,
|
||||
mail.from_real_name, mail)
|
||||
|
||||
def get_leads():
|
||||
if cint(webnotes.conn.get_value('Sales Email Settings', None, 'extract_emails')):
|
||||
|
||||
@@ -33,6 +33,9 @@ class DocType(SellingController):
|
||||
def onload(self):
|
||||
self.add_communication_list()
|
||||
|
||||
def on_communication_sent(self, comm):
|
||||
webnotes.conn.set(self.doc, 'status', 'Replied')
|
||||
|
||||
def check_status(self):
|
||||
chk = sql("select status from `tabLead` where name=%s", self.doc.name)
|
||||
chk = chk and chk[0][0] or ''
|
||||
@@ -90,9 +93,6 @@ class DocType(SellingController):
|
||||
event_user.person = self.doc.contact_by
|
||||
event_user.save()
|
||||
|
||||
def on_communication_sent(self, comm):
|
||||
webnotes.conn.set(self.doc, 'status', 'Replied')
|
||||
|
||||
def get_sender(self, comm):
|
||||
return webnotes.conn.get_value('Sales Email Settings',None,'email_id')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user