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)
79 'state': lambda *a: 'draft',
80 'active': lambda *a: 1,
81 'user_id': lambda self, cr, uid, ctx: uid,
84 def open_meeting(self, cr, uid, ids, context=None):
86 Open Crm Meeting Form for Crm Meeting.
87 @param cr: the current row, from the database cursor,
88 @param uid: the current user’s ID for security checks,
89 @param ids: List of crm meeting’s IDs
90 @param context: A standard dictionary for contextual values
91 @return: Dictionary value which open Crm Meeting form.
97 data_obj = self.pool.get('ir.model.data')
101 id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
102 id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
103 id4 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
105 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
107 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
109 id4 = data_obj.browse(cr, uid, id4, context=context).res_id
112 'name': _('Meeting'),
114 'view_mode': 'form,tree',
115 'res_model': 'crm.meeting',
117 'views': [(id2, 'form'), (id3, 'tree'), (id4, 'calendar')],
118 'type': 'ir.actions.act_window',
119 'res_id': base_calendar.base_calendar_id2real_id(id),
125 def case_open(self, cr, uid, ids, *args):
127 @param self: The object pointer
128 @param cr: the current row, from the database cursor,
129 @param uid: the current user’s ID for security checks,
130 @param ids: List of Meeting Ids
131 @param *args: Tuple Value for additional Params
133 res = super(crm_meeting, self).case_open(cr, uid, ids, args)
134 for (id, name) in self.name_get(cr, uid, ids):
135 message = _("The meeting '%s' has been confirmed.") % name
136 self.log(cr, uid, id, message)
141 class calendar_attendee(osv.osv):
142 """ Calendar Attendee """
144 _inherit = 'calendar.attendee'
145 _description = 'Calendar Attendee'
147 def _compute_data(self, cr, uid, ids, name, arg, context):
149 @param self: The object pointer
150 @param cr: the current row, from the database cursor,
151 @param uid: the current user’s ID for security checks,
152 @param ids: List of compute data’s IDs
153 @param context: A standard dictionary for contextual values
156 result = super(calendar_attendee, self)._compute_data(cr, uid, ids, name, arg, context)
158 for attdata in self.browse(cr, uid, ids, context=context):
161 if name == 'categ_id':
162 if attdata.ref and 'categ_id' in attdata.ref._columns:
163 result[id][name] = (attdata.ref.categ_id.id, attdata.ref.categ_id.name,)
165 result[id][name] = False
169 'categ_id': fields.function(_compute_data, method=True, \
170 string='Event Type', type="many2one", \
171 relation="crm.case.categ", multi='categ_id'),
176 class res_users(osv.osv):
178 _inherit = 'res.users'
180 def create(self, cr, uid, data, context=None):
183 user_id = super(res_users, self).create(cr, uid, data, context)
184 data_obj = self.pool.get('ir.model.data')
186 data_id = data_obj._get_id(cr, uid, 'crm', 'ir_ui_view_sc_calendar0')
187 view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
188 self.pool.get('ir.ui.view_sc').copy(cr, uid, view_id, default = {
189 'user_id': user_id}, context=context)
191 # Tolerate a missing shortcut. See product/product.py for similar code.
192 logging.getLogger('orm').warning('Skipped Products shortcut for user "%s"', data.get('name','<new'))
199 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: