[PYTHON] ~fix bikecoop partner form: studies fields didn't appear when a studie occup...
[burette/eturecup.git] / eturecup.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # eturecup module for OpenERP, Custom module for Étu'Récup
5 # Copyright (C) 2014-2017 Étu'Récup (<http://www.eturecup.org/>)
6 #
7 # This file is a part of eturecup
8 #
9 # eturecup is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # eturecup is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 from openerp.osv import orm
25 from openerp.osv import fields
26
27
28 class Partner(orm.Model):
29 _inherit = 'res.partner'
30
31 def _get_bikecoop_theme_type(self, cr, uid, ids, name, args, context=None):
32 """Return themes type for selected partners"""
33 res = {}
34 partners = self.browse(cr, uid, ids, context=context)
35 for partner in partners:
36 res[partner.id] = False
37 if partner.occupation_id.type == 'studies':
38 res[partner.id] = True
39 return res
40
41 def onchange_occupation_id(self, cr, uid, ids, occupation_id):
42 """Define if a partner is a student based on his/her occupation type"""
43 v = {}
44 partners = self.browse(cr, uid, ids)
45 occupations = self.pool.get('bikecoop.partner.theme')
46 occupation = occupations.browse(cr, uid, occupation_id)
47 if occupation.type == 'studies':
48 v['is_student'] = True
49 else:
50 v['is_student'] = False
51 v['is_scholarship'] = False
52
53 return {'value': v}
54
55 _columns = {
56 'newsletter': fields.boolean(
57 'Do you want to receive our monthly newsletter?'),
58 'is_student': fields.function(_get_bikecoop_theme_type,
59 method=True,
60 string='Student?',
61 type='boolean',
62 store=True),
63 'is_scholarship': fields.boolean('Scholarship',
64 help='Is this student a scholarship?'),
65 'want_to_be_volunteer': fields.boolean(
66 'Do you want to receive some informations about volunteer \
67 activities?',
68 help='… in company and its activities: bikecoop, events, …'),
69 }
70
71 def _check_occupation_is_not_studies(self, cr, uid, ids, context=None):
72 """Check if partners are students. If not, they can't be
73 scholarships."""
74 partners = self.browse(cr, uid, ids, context=context)
75 for partner in partners:
76 if partner.occupation_id.type != 'studies':
77 if partner.is_scholarship:
78 return False
79 return True
80
81 _constraints = [
82 (_check_occupation_is_not_studies, 'Error: This partner can\'t be a\
83 scholarship because s·he isn\'t a student.', ['is_scholarship']),
84 ]
85
86
87 class Theme(orm.Model):
88 _inherit = 'bikecoop.partner.theme'
89
90 _columns = {
91 'type': fields.selection([('studies', 'Studies')],
92 'Type',
93 help='An extra field to categorize themes.'),
94 }
95
96
97 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: