[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,9 +54,15 @@ 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):
if self.doc.contact_by != cstr(self._prev.contact_by) or \
self.doc.contact_date != cstr(self._prev.contact_date):
# delete any earlier event by this lead # delete any earlier event by this lead
sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name) 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",
"owner": self.doc.lead_owner or self.doc.owner,
"subject": ('Contact ' + cstr(self.doc.lead_name)),
"description": ('Contact ' + cstr(self.doc.lead_name)) + \
(self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \
(self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or ''),
ev.event_date = self.doc.contact_date "starts_on": self.doc.contact_date + " 10:00:00",
ev.event_hour = '10:00' "event_type": "Private",
ev.event_type = 'Private' "ref_type": "Lead",
ev.ref_type = 'Lead' "ref_name": self.doc.name
ev.ref_name = self.doc.name },
ev.save(1) {
"doctype": "Event User",
event_user = addchild(ev, 'event_individuals', 'Event User') "parentfield": "event_individuals",
event_user.person = self.doc.contact_by "person": self.doc.contact_by
event_user.save() }
]).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')