1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from osv import fields
28
from tools.translate import _
30
class training_session_create_wizard(osv.osv_memory):
31
_name = 'training.session.create.wizard'
34
'date': fields.datetime('Date', required=True),
35
'name': fields.char('Name', size=64, required=True),
38
def _default_get_name(self, cr, uid, context=None):
41
active_id = context.get('active_id')
44
offer = self.pool.get('training.offer').browse(cr, uid, active_id, context=context)
48
'date': lambda *a: time.strftime('%Y-%m-%d 08:30:00'),
49
'name': _default_get_name,
52
def create_session(self, cr, uid, ids, context=None):
54
pool = pooler.get_pool(cr.dbname)
55
proxy = pool.get('training.offer')
56
offer = proxy.browse(cr, uid, context['active_id'], context=context)
57
for form in self.read(cr, uid, ids, [], context=context):
58
if not offer.can_be_planned:
59
raise osv.except_osv(_('Warning'), _("You can not create a session with a non-validated offer") )
61
proxy = pool.get('training.session')
62
session_id = proxy.create(cr, uid,
64
'offer_id' : offer.id,
65
'date' : form['date'],
66
'name' : "%s (%s)" % (form['name'], time.strftime("%Y-%m-%d", time.strptime(form['date'], '%Y-%m-%d %H:%M:%S'))),
67
'format_id' : offer.format_id.id,
70
vals = proxy.on_change_offer(cr, uid, None, context['active_id'])
71
if isinstance(vals, dict):
72
# we have specified a custom name on session creation,
73
# don't let on_change overwrite it now.
75
if 'name' in vals['value']:
76
del vals['value']['name']
79
proxy.write(cr, uid, [session_id], vals['value'], context=context)
80
session_ids.append(session_id)
81
number_of_sessions = len(session_ids)
82
if not number_of_sessions:
84
elif number_of_sessions == 1:
86
'res_id': int(session_ids[0]),
89
"view_mode": 'form,tree',
90
'res_model': 'training.session',
91
'view_id': pool.get('ir.ui.view').search(cr,uid,[('name','=','training.session.form')]),
92
'type': 'ir.actions.act_window',
97
'domain' : "[('id', 'in', [%s])]" % ','.join(map(str,session_ids)),
100
'view_mode' : 'tree,form',
101
'res_model' : 'training.session',
103
'type' : 'ir.actions.act_window',
107
training_session_create_wizard()