added status to Contact and fix bug in communication pull

This commit is contained in:
Rushabh Mehta 2013-02-11 14:54:30 +05:30
parent af222dc6b2
commit 176829e53c
7 changed files with 55 additions and 45 deletions

View File

@ -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')):

View File

@ -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')

View File

@ -9,6 +9,7 @@ queries = {
"Customer Issue": {"status":"Open"},
"Task": {"status":"Open"},
"Lead": {"status":"Open"},
"Contact": {"status":"Open"},
"Opportunity": {"docstatus":0},
"Quotation": {"docstatus":0},
"Sales Order": {"docstatus":0},

View File

@ -22,7 +22,7 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
}
cur_frm.cscript.refresh = function() {
cur_frm.cscript.refresh = function(doc) {
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"contact": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,

View File

@ -28,6 +28,9 @@ class DocType(TransactionBase):
def onload(self):
self.add_communication_list()
def on_communication_sent(self, comm):
webnotes.conn.set(self.doc, 'status', 'Replied')
def autoname(self):
if self.doc.customer:
self.doc.name = self.doc.first_name + (self.doc.last_name and ' ' + self.doc.last_name or '') + '-' + self.doc.customer

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-10 16:34:32",
"docstatus": 0,
"modified": "2013-01-29 13:26:39",
"modified": "2013-02-11 14:32:13",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -61,6 +61,13 @@
"fieldname": "cb00",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "\nOpen\nReplied"
},
{
"doctype": "DocField",
"fieldname": "email_id",

View File

@ -32,27 +32,8 @@ def send_message(subject="Website Query", message="", sender="", status="Open"):
return
# make lead / communication
name = webnotes.conn.get_value("Lead", {"email_id": sender}, "name")
if name:
lead = webnotes.model_wrapper("Lead", name)
lead.doc.status = status
lead.ignore_permissions = True
lead.save()
else:
lead = webnotes.model_wrapper({
"doctype":"Lead",
"lead_name": sender,
"email_id": sender,
"status": status,
"source": "Website"
})
lead.ignore_permissions = True
lead.insert()
make(content=message, sender=sender, subject=subject,
doctype="Lead", name=lead.doc.name, lead=lead.doc.name)
from selling.doctype.lead.get_leads import add_sales_communication
add_sales_communication(subject or "Website Query", message, sender, sender)
# guest method, cap max writes per hour
if webnotes.conn.sql("""select count(*) from `tabCommunication`