1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 base_calendar import base_calendar
23 from crm import crm_case
24 from osv import fields, osv
25 from tools.translate import _
28 class crm_lead(crm_case, osv.osv):
33 class crm_phonecall(crm_case, osv.osv):
35 _name = 'crm.phonecall'
39 class crm_meeting(crm_case, osv.osv):
40 """ CRM Meeting Cases """
43 _description = "Meeting"
45 _inherit = ['mailgate.thread',"calendar.event"]
48 'name': fields.char('Summary', size=124, required=True, states={'done': [('readonly', True)]}),
49 'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)]}),
50 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
51 domain="[('partner_id','=',partner_id)]", states={'done': [('readonly', True)]}),
52 'section_id': fields.many2one('crm.case.section', 'Sales Team', states={'done': [('readonly', True)]}, \
53 select=True, help='Sales team to which Case belongs to.'),
54 'email_from': fields.char('Email', size=128, states={'done': [('readonly', True)]}, help="These people will receive email."),
55 'id': fields.integer('ID'),
56 'create_date': fields.datetime('Creation Date' , readonly=True),
57 'write_date': fields.datetime('Write Date' , readonly=True),
58 'date_action_last': fields.datetime('Last Action', readonly=1),
59 'date_action_next': fields.datetime('Next Action', readonly=1),
61 'categ_id': fields.many2one('crm.case.categ', 'Meeting Type', \
62 domain="[('object_id.model', '=', 'crm.meeting')]", \
64 'phonecall_id': fields.many2one ('crm.phonecall', 'Phonecall'),
65 'opportunity_id': fields.many2one ('crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]"),
66 'attendee_ids': fields.many2many('calendar.attendee', 'meeting_attendee_rel',\
67 'event_id', 'attendee_id', 'Attendees', states={'done': [('readonly', True)]}),
68 'date_closed': fields.datetime('Closed', readonly=True),
69 'date_deadline': fields.datetime('Deadline', states={'done': [('readonly', True)]}),
70 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
71 'state': fields.selection([('open', 'Confirmed'),
72 ('draft', 'Unconfirmed'),
73 ('cancel', 'Cancelled'),
74 ('done', 'Done')], 'State', \
75 size=16, readonly=True),
78 'state': lambda *a: 'draft',
79 'active': lambda *a: 1,
80 'user_id': lambda self, cr, uid, ctx: uid,
83 def case_open(self, cr, uid, ids, *args):
85 @param self: The object pointer
86 @param cr: the current row, from the database cursor,
87 @param uid: the current user’s ID for security checks,
88 @param ids: List of Meeting Ids
89 @param *args: Tuple Value for additional Params
91 res = super(crm_meeting, self).case_open(cr, uid, ids, args)
92 for (id, name) in self.name_get(cr, uid, ids):
93 message = _("The meeting '%s' has been confirmed.") % name
94 id=base_calendar.base_calendar_id2real_id(id)
95 self.log(cr, uid, id, message)
100 class calendar_attendee(osv.osv):
101 """ Calendar Attendee """
103 _inherit = 'calendar.attendee'
104 _description = 'Calendar Attendee'
106 def _compute_data(self, cr, uid, ids, name, arg, context=None):
108 @param self: The object pointer
109 @param cr: the current row, from the database cursor,
110 @param uid: the current user’s ID for security checks,
111 @param ids: List of compute data’s IDs
112 @param context: A standard dictionary for contextual values
115 result = super(calendar_attendee, self)._compute_data(cr, uid, ids, name, arg, context=context)
117 for attdata in self.browse(cr, uid, ids, context=context):
120 if name == 'categ_id':
121 if attdata.ref and 'categ_id' in attdata.ref._columns:
122 result[id][name] = (attdata.ref.categ_id.id, attdata.ref.categ_id.name,)
124 result[id][name] = False
128 'categ_id': fields.function(_compute_data, method=True, \
129 string='Event Type', type="many2one", \
130 relation="crm.case.categ", multi='categ_id'),
135 class res_users(osv.osv):
137 _inherit = 'res.users'
139 def create(self, cr, uid, data, context=None):
140 user_id = super(res_users, self).create(cr, uid, data, context=context)
141 data_obj = self.pool.get('ir.model.data')
143 data_id = data_obj._get_id(cr, uid, 'crm', 'ir_ui_view_sc_calendar0')
144 view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
145 self.pool.get('ir.ui.view_sc').copy(cr, uid, view_id, default = {
146 'user_id': user_id}, context=context)
148 # Tolerate a missing shortcut. See product/product.py for similar code.
149 logging.getLogger('orm').warning('Skipped Products shortcut for user "%s"', data.get('name','<new'))
156 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: