From c08e198cd25cf26dc9a1aff816e53384dfb2c76c Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Thu, 4 Mar 2010 15:24:42 +0530 Subject: [PATCH] [IMP]: crm(Meetings): * Changed logic of duration/End date computation form function field to onchange * Removed timezone and priority * Removed unrelated states * Improved invitation+invitation accept logic bzr revid: rpa@openerp.co.in-20100304095442-8ke1gvtr1avs6n0t --- addons/base_calendar/base_calendar.py | 90 +++++++++++++-------------- addons/crm/crm_meeting.py | 28 ++++++--- addons/crm/crm_meeting_demo.xml | 8 +-- addons/crm/crm_meeting_view.xml | 46 +++++++++----- 4 files changed, 93 insertions(+), 79 deletions(-) diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 82ceb2aab70..b2ca2af3b0b 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -202,6 +202,10 @@ class invite_attendee_wizard(osv.osv_memory): to send an Email to Invited Person') } + _defaults = { + 'type': lambda *x: 'internal' + } + def do_invite(self, cr, uid, ids, context={}): datas = self.read(cr, uid, ids)[0] model = False @@ -224,12 +228,10 @@ class invite_attendee_wizard(osv.osv_memory): user_obj = self.pool.get('res.users') for user_id in datas.get('user_ids', []): user = user_obj.browse(cr, uid, user_id) - if not user.address_id.email: - raise osv.except_osv(_('Error!'), \ - ("User does not have an email Address")) vals.update({'user_id': user_id, 'email': user.address_id.email}) - mail_to.append(user.address_id.email) + if user.address_id.email: + mail_to.append(user.address_id.email) elif type == 'external' and datas.get('email'): vals.update({'email': datas['email']}) @@ -237,13 +239,11 @@ class invite_attendee_wizard(osv.osv_memory): elif type == 'partner': add_obj = self.pool.get('res.partner.address') for contact in add_obj.browse(cr, uid, datas['contact_ids']): - if not contact.email: - raise osv.except_osv(_('Error!'), \ - ("Partner does not have an email Address")) vals.update({ 'partner_address_id': contact.id, 'email': contact.email}) - mail_to.append(contact.email) + if contact.email: + mail_to.append(contact.email) if model == 'calendar.attendee': att = att_obj.browse(cr, uid, context['active_id']) @@ -256,9 +256,14 @@ class invite_attendee_wizard(osv.osv_memory): obj.write(cr, uid, res_obj.id, {model_field: [(4, att_id)]}) if datas.get('send_mail'): + if not mail_to: + name = map(lambda x: x[1], filter(lambda x: type==x[0], \ + self._columns['type'].selection)) + raise osv.except_osv(_('Error!'), ("%s must have an email \ +Address to send mail") % (name[0])) att_obj._send_mail(cr, uid, [att_id], mail_to, \ email_from=tools.config.get('email_from', False)) - + return {} @@ -268,10 +273,6 @@ class invite_attendee_wizard(osv.osv_memory): cr.execute('select id from res_partner_address \ where partner_id=%s' % (partner_id)) contacts = map(lambda x: x[0], cr.fetchall()) - if not contacts: - raise osv.except_osv(_('Error!'), \ - ("Partner does not have any Contacts")) - return {'value': {'contact_ids': contacts}} invite_attendee_wizard() @@ -398,7 +399,7 @@ request was delegated to"), 'user_id': fields.many2one('res.users', 'User'), 'partner_address_id': fields.many2one('res.partner.address', 'Contact'), 'partner_id': fields.related('partner_address_id', 'partner_id', type='many2one', relation='res.partner', string='Partner', help="Partner related to contact"), - 'email': fields.char('Email', size=124, required=True, help="Email of Invited Person"), + 'email': fields.char('Email', size=124, help="Email of Invited Person"), 'event_date': fields.function(_compute_data, method=True, string='Event Date', type="datetime", multi='event_date'), 'event_end_date': fields.function(_compute_data, method=True, string='Event End Date', type="datetime", multi='event_end_date'), 'ref': fields.reference('Event Ref', selection=_links_get, size=128), @@ -480,6 +481,17 @@ request was delegated to"), self.write(cr, uid, ids, {'state': 'tentative'}, context) def do_accept(self, cr, uid, ids, context=None, *args): + vals = self.read(cr, uid, ids, context=context)[0] + user = vals.get('user_id') + if user: + ref = vals.get('ref', None) + if ref: + model, event = ref.split(',') + model_obj = self.pool.get(model) + event_ref = model_obj.browse(cr, uid, event, context=context)[0] + if event_ref.user_id.id != user[0]: + defaults = {'user_id': user[0]} + new_event = model_obj.copy(cr, uid, event, default=defaults, context=context) self.write(cr, uid, ids, {'state': 'accepted'}, context) def do_decline(self, cr, uid, ids, context=None, *args): @@ -708,26 +720,21 @@ class calendar_event(osv.osv): 'interval': 1}) return {'value': {'rrule': rrulestr}} - def _get_duration(self, cr, uid, ids, name, arg, context): - res = {} - for event in self.browse(cr, uid, ids, context=context): - start = datetime.strptime(event.date, "%Y-%m-%d %H:%M:%S") - res[event.id] = 0 - if event.date_deadline: - end = datetime.strptime(event.date_deadline[:19], "%Y-%m-%d %H:%M:%S") - diff = end - start - duration = float(diff.days)* 24 + (float(diff.seconds) / 3600) - res[event.id] = round(duration, 2) - return res + def onchange_dates(self, cr, uid, ids, start_date, duration=False, end_date=False, context={}): + if not start_date: + return {} + start = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S") + value = {} + if end_date and not duration: + end = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S") + diff = end - start + duration = float(diff.days)* 24 + (float(diff.seconds) / 3600) + value['duration'] = round(duration, 2) + elif not end_date: + end = start + timedelta(hours=duration) + value['date_deadline'] = end.strftime("%Y-%m-%d %H:%M:%S") + return {'value': value} - def _set_duration(self, cr, uid, id, name, value, arg, context): - event = self.browse(cr, uid, id, context=context) - start = datetime.strptime(event.date, "%Y-%m-%d %H:%M:%S") - end = start + timedelta(hours=value) - cr.execute("UPDATE %s set date_deadline='%s' \ - where id=%s"% (self._table, end.strftime("%Y-%m-%d %H:%M:%S"), id)) - return True - _columns = { 'id': fields.integer('ID'), 'sequence': fields.integer('Sequence'), @@ -735,8 +742,7 @@ class calendar_event(osv.osv): 'date': fields.datetime('Date'), 'date_deadline': fields.datetime('Deadline'), 'create_date': fields.datetime('Created', readonly=True), - 'duration': fields.function(_get_duration, method=True, \ - fnct_inv=_set_duration, string='Duration'), + 'duration': fields.float('Duration'), 'description': fields.text('Your action'), 'class': fields.selection([('public', 'Public'), ('private', 'Private'), \ ('confidential', 'Confidential')], 'Mark as'), @@ -757,25 +763,15 @@ rule or repeating pattern for anexception to a recurrence set"), 'base_calendar_alarm_id': fields.many2one('calendar.alarm', 'Alarm'), 'recurrent_uid': fields.integer('Recurrent ID'), 'recurrent_id': fields.datetime('Recurrent ID date'), - 'vtimezone': fields.selection(_tz_get, 'Timezone', size=64), + 'vtimezone': fields.related('user_id', 'context_tz', type='char', size=24, string='Timezone'), 'user_id': fields.many2one('res.users', 'Responsible'), } - + _defaults = { 'class': lambda *a: 'public', 'show_as': lambda *a: 'busy', } - def onchange_user_id(self, cr, uid, ids, user_id, *args, **argv): - if not user_id: - return {'value': {'vtimezone': False}} - value = {'vtimezone': False} - cr.execute('select context_tz from res_users where id=%s' % (user_id)) - timezone = cr.fetchone()[0] - if timezone: - value.update({'vtimezone': timezone.lower()}) - return {'value': value} - def modify_this(self, cr, uid, ids, defaults, context=None, *args): datas = self.read(cr, uid, ids[0], context=context) defaults.update({ diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py index 4027c097227..ce818fa0189 100644 --- a/addons/crm/crm_meeting.py +++ b/addons/crm/crm_meeting.py @@ -41,17 +41,25 @@ class crm_meeting(osv.osv): _inherit = ["crm.case", "calendar.event"] _columns = { - 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), 'categ_id': fields.many2one('crm.case.categ', 'Meeting Type', \ - domain="[('object_id.model', '=', 'crm.meeting')]", \ - ), - 'phonecall_id':fields.many2one ('crm.phonecall', 'Phonecall'), - 'opportunity_id':fields.many2one ('crm.opportunity', 'Opportunity'), - 'attendee_ids': fields.many2many('calendar.attendee', 'event_attendee_rel', 'event_id', 'attendee_id', 'Attendees'), + domain="[('object_id.model', '=', 'crm.meeting')]", \ + ), + 'phonecall_id':fields.many2one ('crm.phonecall', 'Phonecall'), + 'opportunity_id':fields.many2one ('crm.opportunity', 'Opportunity'), + 'attendee_ids': fields.many2many('calendar.attendee', 'event_attendee_rel', 'event_id', 'attendee_id', 'Attendees'), 'date_closed': fields.datetime('Closed', readonly=True), - 'date_deadline': fields.datetime('Deadline'), + 'date_deadline': fields.datetime('Deadline'), + 'state': fields.selection([('open', 'Confirmed'), + ('draft', 'Unconfirmed'), + ('cancel', 'Cancelled'), + ('done', 'Done')], 'State', \ + size=16, readonly=True) } - + + _defaults = { + 'state': lambda *a: 'draft', + } + crm_meeting() class calendar_attendee(osv.osv): @@ -74,7 +82,9 @@ class calendar_attendee(osv.osv): result[id][name] = False return result _columns = { - 'categ_id': fields.function(_compute_data, method=True, string='Event Type', type="many2one", relation="crm.case.categ", multi='categ_id'), + 'categ_id': fields.function(_compute_data, method=True, \ + string='Event Type', type="many2one", \ + relation="crm.case.categ", multi='categ_id'), } calendar_attendee() diff --git a/addons/crm/crm_meeting_demo.xml b/addons/crm/crm_meeting_demo.xml index 4eefc6c1042..a43f3e0d571 100644 --- a/addons/crm/crm_meeting_demo.xml +++ b/addons/crm/crm_meeting_demo.xml @@ -10,7 +10,6 @@ - @@ -27,7 +26,6 @@ - @@ -43,7 +41,6 @@ - @@ -59,7 +56,6 @@ - @@ -74,9 +70,8 @@ - - + @@ -89,7 +84,6 @@ - diff --git a/addons/crm/crm_meeting_view.xml b/addons/crm/crm_meeting_view.xml index 40b9f7ecef8..cff4bc09aeb 100644 --- a/addons/crm/crm_meeting_view.xml +++ b/addons/crm/crm_meeting_view.xml @@ -29,9 +29,9 @@ - - - + + + @@ -59,14 +59,11 @@ on_change="onchange_partner_address_id(partner_address_id, email_from)" /> - - - + + - - @@ -75,13 +72,16 @@ - -