[lead] [next contact] [fix] create event

This commit is contained in:
Anand Doshi
2013-06-10 12:34:31 +05:30
parent eec70e73ba
commit b2dc1aeca9

View File

@@ -17,8 +17,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes import _ from webnotes import _
from webnotes.utils import cstr, validate_email_add from webnotes.utils import cstr, validate_email_add, cint
from webnotes.model.doc import Document, addchild
from webnotes import session, msgprint from webnotes import session, msgprint
sql = webnotes.conn.sql sql = webnotes.conn.sql
@@ -54,11 +53,17 @@ class DocType(SellingController):
if not validate_email_add(self.doc.email_id): if not validate_email_add(self.doc.email_id):
msgprint('Please enter valid email id.') msgprint('Please enter valid email id.')
raise Exception raise Exception
self._prev = webnotes._dict({
"contact_date": webnotes.conn.get_value("Lead", self.doc.name, "contact_date") if \
(not cint(self.doc.fields.get("__islocal"))) else None,
"contact_by": webnotes.conn.get_value("Lead", self.doc.name, "contact_by") if \
(not cint(self.doc.fields.get("__islocal"))) else None,
})
def on_update(self): def on_update(self):
if self.doc.contact_date: self.add_calendar_event()
self.add_calendar_event()
self.check_email_id_is_unique() self.check_email_id_is_unique()
@@ -73,25 +78,33 @@ class DocType(SellingController):
", ".join(items), raise_exception=True) ", ".join(items), raise_exception=True)
def add_calendar_event(self): def add_calendar_event(self):
# delete any earlier event by this lead if self.doc.contact_by != cstr(self._prev.contact_by) or \
sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name) self.doc.contact_date != cstr(self._prev.contact_date):
# delete any earlier event by this lead
# create new event for name in webnotes.conn.sql_list("""select name from `tabEvent`
ev = Document('Event') where ref_type="Lead" and ref_name=%s""", self.doc.name):
ev.owner = self.doc.lead_owner webnotes.delete_doc("Event", name)
ev.description = ('Contact ' + cstr(self.doc.lead_name)) + \
(self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ if self.doc.contact_date:
(self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') webnotes.bean([
ev.event_date = self.doc.contact_date {
ev.event_hour = '10:00' "doctype": "Event",
ev.event_type = 'Private' "owner": self.doc.lead_owner or self.doc.owner,
ev.ref_type = 'Lead' "subject": ('Contact ' + cstr(self.doc.lead_name)),
ev.ref_name = self.doc.name "description": ('Contact ' + cstr(self.doc.lead_name)) + \
ev.save(1) (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \
(self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or ''),
event_user = addchild(ev, 'event_individuals', 'Event User') "starts_on": self.doc.contact_date + " 10:00:00",
event_user.person = self.doc.contact_by "event_type": "Private",
event_user.save() "ref_type": "Lead",
"ref_name": self.doc.name
},
{
"doctype": "Event User",
"parentfield": "event_individuals",
"person": self.doc.contact_by
}
]).insert()
def get_sender(self, comm): def get_sender(self, comm):
return webnotes.conn.get_value('Sales Email Settings',None,'email_id') return webnotes.conn.get_value('Sales Email Settings',None,'email_id')