~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to training/wizard/participation_reassign.py

  • Committer: Albert Cervera i Areny
  • Date: 2011-06-14 09:51:35 UTC
  • mfrom: (5345.1.165 openobject-addons)
  • Revision ID: albert@nan-tic.com-20110614095135-1x3p6tmil5lxkl9b
Merge and add nan_remove_default_filters

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
############################################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    Copyright (C) 2008-2009 AJM Technologies S.A. (<http://www.ajm.lu>). All Rights Reserved
 
7
#    Copyright (C) 2010 Zikzakmedia S.L. (<http://www.zikzakmedia.com>). All Rights Reserved
 
8
#    $Id$
 
9
#
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
#
 
23
############################################################################################
 
24
 
 
25
from osv import osv, fields
 
26
from tools.translate import _
 
27
 
 
28
class training_participation_reassign_wizard(osv.osv_memory):
 
29
    _name = 'training.participation.reassign.wizard'
 
30
 
 
31
    _columns = {
 
32
        'participation_id' : fields.many2one('training.participation', 'Participation', required=True),
 
33
        'participation_seance_id' : fields.related('participation_id', 'seance_id', type='many2one', relation='training.seance', readonly=True, string='Seance'),
 
34
        'participation_seance_date' : fields.related('participation_id', 'seance_id', 'date', type='datetime', readonly=True, string='Date'),
 
35
        'participation_sl' : fields.related('participation_id', 'subscription_line_id', type='many2one', relation='training.subscription.line', readonly=True, string='Subscription Line'),
 
36
        'participation_session_id' : fields.related('participation_id', 'subscription_line_id', 'session_id', type='many2one', relation='training.session',
 
37
                                                    readonly=True,
 
38
                                                    string='Session'),
 
39
        'seance_id' : fields.many2one('training.seance', 'Seance',
 
40
                                      #domain="[('session_ids', 'in', [participation_session_id])]",
 
41
                                      required=True),
 
42
    }
 
43
 
 
44
    def on_change_seance(self, cr, uid, ids, seance_id, context=None):
 
45
        values = {
 
46
            'domain' : {
 
47
                'participation_id' : not seance_id and [] or [('seance_id', '=', seance_id)],
 
48
            }
 
49
        }
 
50
 
 
51
        return values
 
52
 
 
53
    def on_change_participation(self, cr, uid, ids, participation_id, context=None):
 
54
        if not participation_id:
 
55
            return {
 
56
                'value' : {
 
57
                    'seance_id' : 0,
 
58
                },
 
59
                'domain' : {
 
60
                    'seance_id' : [],
 
61
                },
 
62
            }
 
63
 
 
64
        p = self.pool.get('training.participation').browse(cr, uid, participation_id, context=context)
 
65
        return {
 
66
            'value' : {
 
67
                'participation_seance_id' : p.seance_id.id,
 
68
                'participation_seance_date' : p.seance_id.date,
 
69
                'participation_sl' : p.subscription_line_id.id,
 
70
                'participation_session_id' : p.subscription_line_id.session_id.id,
 
71
            },
 
72
            'domain' : {
 
73
                'seance_id' : [('id', 'in', [seance.id for seance in p.subscription_line_id.session_id.seance_ids])],
 
74
            }
 
75
        }
 
76
 
 
77
    def close_cb(self, cr, uid, ids, context=None):
 
78
        return {'type' : 'ir.actions.act_window_close'}
 
79
 
 
80
    def apply_cb(self, cr, uid, ids, context=None):
 
81
        this = self.browse(cr, uid, ids[0], context=context)
 
82
 
 
83
        if this.participation_id.seance_id == this.seance_id:
 
84
            raise osv.except_osv(_('Warning'),
 
85
                                 _('You have selected the same seance'))
 
86
 
 
87
        this.participation_id.write({'seance_id' : this.seance_id.id})
 
88
 
 
89
        return {'type' : 'ir.actions.act_window_close'}
 
90
 
 
91
training_participation_reassign_wizard()
 
92