[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
@@ -55,10 +54,16 @@ class DocType(SellingController):
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
for name in webnotes.conn.sql_list("""select name from `tabEvent`
where ref_type="Lead" and ref_name=%s""", self.doc.name):
webnotes.delete_doc("Event", name)
# create new event if self.doc.contact_date:
ev = Document('Event') webnotes.bean([
ev.owner = self.doc.lead_owner {
ev.description = ('Contact ' + cstr(self.doc.lead_name)) + \ "doctype": "Event",
(self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ "owner": self.doc.lead_owner or self.doc.owner,
(self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') "subject": ('Contact ' + cstr(self.doc.lead_name)),
ev.event_date = self.doc.contact_date "description": ('Contact ' + cstr(self.doc.lead_name)) + \
ev.event_hour = '10:00' (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \
ev.event_type = 'Private' (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or ''),
ev.ref_type = 'Lead' "starts_on": self.doc.contact_date + " 10:00:00",
ev.ref_name = self.doc.name "event_type": "Private",
ev.save(1) "ref_type": "Lead",
"ref_name": self.doc.name
event_user = addchild(ev, 'event_individuals', 'Event User') },
event_user.person = self.doc.contact_by {
event_user.save() "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')