1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-today OpenERP SA (<http://www.openerp.com>)
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
24 from tools.translate import _
26 _logger = logging.getLogger(__name__)
29 # crm.meeting is defined in module base_calendar
31 class crm_meeting(osv.Model):
32 """ Model for CRM meetings """
33 _inherit = 'crm.meeting'
35 'phonecall_id': fields.many2one ('crm.phonecall', 'Phonecall'),
36 'opportunity_id': fields.many2one ('crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]"),
39 def create(self, cr, uid, vals, context=None):
40 obj_id = super(crm_meeting, self).create(cr, uid, vals, context=context)
41 self.create_send_note(cr, uid, [obj_id], context=context)
44 def create_send_note(self, cr, uid, ids, context=None):
47 # update context: if come from phonecall, default state values can make the message_append_note crash
48 context.pop('default_state', False)
49 for meeting in self.browse(cr, uid, ids, context=context):
50 # in the message, transpose meeting.date to the timezone of the current user
51 meeting_date = fields.DT.datetime.strptime(meeting.date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
52 meeting_date_tz = fields.datetime.context_timestamp(cr, uid, meeting_date, context=context).strftime(tools.DATETIME_FORMATS_MAP['%+'] + " (%Z)")
53 if meeting.opportunity_id: # meeting can be create from phonecalls or opportunities, therefore checking for the parent
54 lead = meeting.opportunity_id
55 message = _("Meeting linked to the opportunity <em>%s</em> has been <b>created</b> and <b>scheduled</b> on <em>%s</em>.") % (lead.name, meeting_date_tz)
56 lead.message_append_note(_('System Notification'), message)
57 elif meeting.phonecall_id:
58 phonecall = meeting.phonecall_id
59 message = _("Meeting linked to the phonecall <em>%s</em> has been <b>created</b> and <b>scheduled</b> on <em>%s</em>.") % (phonecall.name, meeting_date_tz)
60 phonecall.message_append_note(body=message)
62 message = _("A meeting has been <b>scheduled</b> on <em>%s</em>.") % (meeting_date_tz)
63 meeting.message_append_note(body=message)
66 class calendar_attendee(osv.osv):
67 """ Calendar Attendee """
69 _inherit = 'calendar.attendee'
70 _description = 'Calendar Attendee'
72 def _compute_data(self, cr, uid, ids, name, arg, context=None):
74 @param self: The object pointer
75 @param cr: the current row, from the database cursor,
76 @param uid: the current user’s ID for security checks,
77 @param ids: List of compute data’s IDs
78 @param context: A standard dictionary for contextual values
81 result = super(calendar_attendee, self)._compute_data(cr, uid, ids, name, arg, context=context)
83 for attdata in self.browse(cr, uid, ids, context=context):
86 if name == 'categ_id':
87 if attdata.ref and 'categ_id' in attdata.ref._columns:
88 result[id][name] = (attdata.ref.categ_id.id, attdata.ref.categ_id.name,)
90 result[id][name] = False
94 'categ_id': fields.function(_compute_data, \
95 string='Event Type', type="many2one", \
96 relation="crm.case.categ", multi='categ_id'),
99 class res_users(osv.osv):
101 _inherit = 'res.users'
103 def create(self, cr, uid, data, context=None):
104 user_id = super(res_users, self).create(cr, uid, data, context=context)
106 # add shortcut unless 'noshortcut' is True in context
107 if not(context and context.get('noshortcut', False)):
108 data_obj = self.pool.get('ir.model.data')
110 data_id = data_obj._get_id(cr, uid, 'crm', 'ir_ui_view_sc_calendar0')
111 view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
112 self.pool.get('ir.ui.view_sc').copy(cr, uid, view_id, default = {
113 'user_id': user_id}, context=context)
115 # Tolerate a missing shortcut. See product/product.py for similar code.
116 _logger.debug('Skipped meetings shortcut for user "%s".', data.get('name','<new'))
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: