2010-03-23 14:42:41 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
|
|
|
|
#
|
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2012-01-09 15:10:55 +00:00
|
|
|
|
from .. import base_calendar
|
2010-03-23 14:42:41 +00:00
|
|
|
|
from osv import fields, osv
|
2010-03-25 13:05:11 +00:00
|
|
|
|
from tools.translate import _
|
2010-03-25 11:53:54 +00:00
|
|
|
|
import tools
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
2010-03-25 13:05:11 +00:00
|
|
|
|
|
2010-03-23 14:42:41 +00:00
|
|
|
|
class base_calendar_invite_attendee(osv.osv_memory):
|
|
|
|
|
"""
|
|
|
|
|
Invite attendee.
|
|
|
|
|
"""
|
2010-03-25 12:07:00 +00:00
|
|
|
|
|
2010-03-23 14:42:41 +00:00
|
|
|
|
_name = "base_calendar.invite.attendee"
|
|
|
|
|
_description = "Invite Attendees"
|
|
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
|
'type': fields.selection([('internal', 'Internal User'), \
|
|
|
|
|
('external', 'External Email'), \
|
2010-10-01 13:46:41 +00:00
|
|
|
|
('partner', 'Partner Contacts')], 'Type', required=True, help="Select whom you want to Invite"),
|
2010-03-25 12:07:00 +00:00
|
|
|
|
'user_ids': fields.many2many('res.users', 'invite_user_rel',
|
|
|
|
|
'invite_id', 'user_id', 'Users'),
|
|
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner'),
|
2010-10-01 13:46:41 +00:00
|
|
|
|
'email': fields.char('Email', size=124, help="Provide external email address who will receive this invitation."),
|
2012-03-05 09:30:39 +00:00
|
|
|
|
'contact_ids': fields.many2many('res.partner', 'invite_contact_rel',
|
2010-03-25 12:07:00 +00:00
|
|
|
|
'invite_id', 'contact_id', 'Contacts'),
|
|
|
|
|
'send_mail': fields.boolean('Send mail?', help='Check this if you want to \
|
2010-05-12 13:16:01 +00:00
|
|
|
|
send an Email to Invited Person')
|
2010-03-24 15:57:18 +00:00
|
|
|
|
}
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
|
|
|
|
_defaults = {
|
2010-09-03 13:34:50 +00:00
|
|
|
|
'type': 'internal',
|
|
|
|
|
'send_mail': True
|
2010-03-24 15:57:18 +00:00
|
|
|
|
}
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
|
|
|
|
def do_invite(self, cr, uid, ids, context=None):
|
|
|
|
|
"""
|
|
|
|
|
Invites attendee for meeting..
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of base calendar invite attendee’s IDs.
|
|
|
|
|
@param context: A standard dictionary for contextual values
|
|
|
|
|
@return: Dictionary of {}.
|
|
|
|
|
"""
|
2010-03-25 12:07:00 +00:00
|
|
|
|
|
2010-11-23 07:05:05 +00:00
|
|
|
|
if context is None:
|
2010-03-23 14:42:41 +00:00
|
|
|
|
context = {}
|
2010-03-25 12:07:00 +00:00
|
|
|
|
|
2010-03-24 15:57:18 +00:00
|
|
|
|
model = False
|
|
|
|
|
context_id = context and context.get('active_id', False) or False
|
|
|
|
|
if not context or not context.get('model'):
|
2010-12-28 10:44:45 +00:00
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-03-24 15:57:18 +00:00
|
|
|
|
else:
|
|
|
|
|
model = context.get('model')
|
2010-05-13 11:37:59 +00:00
|
|
|
|
|
2010-03-24 15:57:18 +00:00
|
|
|
|
model_field = context.get('attendee_field', False)
|
2010-05-13 11:37:59 +00:00
|
|
|
|
obj = self.pool.get(model)
|
2010-11-19 13:48:01 +00:00
|
|
|
|
res_obj = obj.browse(cr, uid, context_id, context=context)
|
2010-05-13 11:37:59 +00:00
|
|
|
|
att_obj = self.pool.get('calendar.attendee')
|
2010-07-09 13:35:29 +00:00
|
|
|
|
user_obj = self.pool.get('res.users')
|
|
|
|
|
current_user = user_obj.browse(cr, uid, uid, context=context)
|
2012-07-20 12:12:46 +00:00
|
|
|
|
|
2010-03-24 15:57:18 +00:00
|
|
|
|
for datas in self.read(cr, uid, ids, context=context):
|
2010-03-23 14:42:41 +00:00
|
|
|
|
type = datas.get('type')
|
|
|
|
|
vals = []
|
|
|
|
|
mail_to = []
|
|
|
|
|
attendees = []
|
|
|
|
|
ref = {}
|
|
|
|
|
|
|
|
|
|
if not model == 'calendar.attendee':
|
|
|
|
|
if context_id:
|
|
|
|
|
ref = {'ref': '%s,%s' % (model, base_calendar.base_calendar_id2real_id(context_id))}
|
2010-03-25 12:07:00 +00:00
|
|
|
|
else:
|
2010-12-28 10:44:45 +00:00
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-03-23 14:42:41 +00:00
|
|
|
|
if type == 'internal':
|
2012-08-06 16:28:17 +00:00
|
|
|
|
|
2010-03-23 14:42:41 +00:00
|
|
|
|
if not datas.get('user_ids'):
|
2012-07-25 11:55:11 +00:00
|
|
|
|
raise osv.except_osv(_('Error!'), ("Please select any user."))
|
2010-03-23 14:42:41 +00:00
|
|
|
|
for user_id in datas.get('user_ids'):
|
|
|
|
|
user = user_obj.browse(cr, uid, user_id)
|
|
|
|
|
res = {
|
2010-03-25 12:07:00 +00:00
|
|
|
|
'user_id': user_id,
|
2012-08-10 10:22:57 +00:00
|
|
|
|
'email': user.email
|
2010-03-23 14:42:41 +00:00
|
|
|
|
}
|
|
|
|
|
res.update(ref)
|
|
|
|
|
vals.append(res)
|
2012-08-10 10:22:57 +00:00
|
|
|
|
if user.email:
|
|
|
|
|
mail_to.append(user.email)
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
|
|
|
|
elif type == 'external' and datas.get('email'):
|
|
|
|
|
res = {'email': datas['email']}
|
|
|
|
|
res.update(ref)
|
|
|
|
|
vals.append(res)
|
|
|
|
|
mail_to.append(datas['email'])
|
|
|
|
|
|
|
|
|
|
elif type == 'partner':
|
2012-03-05 09:30:39 +00:00
|
|
|
|
add_obj = self.pool.get('res.partner')
|
2010-03-23 14:42:41 +00:00
|
|
|
|
for contact in add_obj.browse(cr, uid, datas['contact_ids']):
|
|
|
|
|
res = {
|
2012-03-05 09:30:39 +00:00
|
|
|
|
'partner_id': contact.id,
|
2010-03-23 14:42:41 +00:00
|
|
|
|
'email': contact.email
|
|
|
|
|
}
|
|
|
|
|
res.update(ref)
|
|
|
|
|
vals.append(res)
|
|
|
|
|
if contact.email:
|
|
|
|
|
mail_to.append(contact.email)
|
|
|
|
|
|
|
|
|
|
for att_val in vals:
|
|
|
|
|
if model == 'calendar.attendee':
|
2010-05-13 11:37:59 +00:00
|
|
|
|
att = att_obj.browse(cr, uid, context_id)
|
|
|
|
|
att_val.update({
|
|
|
|
|
'parent_ids': [(4, att.id)],
|
2010-09-20 11:37:45 +00:00
|
|
|
|
'ref': att.ref and (att.ref._name + ',' +str(att.ref.id)) or False
|
2010-05-13 11:37:59 +00:00
|
|
|
|
})
|
2010-09-20 11:37:45 +00:00
|
|
|
|
|
2010-03-23 14:42:41 +00:00
|
|
|
|
attendees.append(att_obj.create(cr, uid, att_val))
|
|
|
|
|
if model_field:
|
|
|
|
|
for attendee in attendees:
|
|
|
|
|
obj.write(cr, uid, res_obj.id, {model_field: [(4, attendee)]})
|
|
|
|
|
|
|
|
|
|
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))
|
2012-08-06 16:28:17 +00:00
|
|
|
|
raise osv.except_osv(_('Error!'), _("%s must have an email address to send mail.") %(name[0]))
|
2010-03-23 14:42:41 +00:00
|
|
|
|
att_obj._send_mail(cr, uid, attendees, mail_to, \
|
2012-08-10 10:22:57 +00:00
|
|
|
|
email_from = current_user.email or tools.config.get('email_from', False))
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
2010-12-28 10:44:45 +00:00
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-03-23 14:42:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def onchange_partner_id(self, cr, uid, ids, partner_id, *args, **argv):
|
|
|
|
|
"""
|
|
|
|
|
Make entry on contact_ids on change of partner_id field.
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of base calendar invite attendee’s IDs.
|
2010-03-25 12:07:00 +00:00
|
|
|
|
@param partner_id: id of Partner
|
2010-03-23 14:42:41 +00:00
|
|
|
|
@return: dictionary of value.
|
|
|
|
|
"""
|
2010-03-25 12:07:00 +00:00
|
|
|
|
|
2010-03-23 14:42:41 +00:00
|
|
|
|
if not partner_id:
|
|
|
|
|
return {'value': {'contact_ids': []}}
|
2012-03-05 09:30:39 +00:00
|
|
|
|
cr.execute('SELECT id FROM res_partner \
|
2012-03-05 11:52:12 +00:00
|
|
|
|
WHERE id=%s or parent_id =%s' , (partner_id,partner_id,))
|
2010-03-23 14:42:41 +00:00
|
|
|
|
contacts = map(lambda x: x[0], cr.fetchall())
|
|
|
|
|
return {'value': {'contact_ids': contacts}}
|
|
|
|
|
|
|
|
|
|
base_calendar_invite_attendee()
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|