X-Git-Url: http://git.cyclocoop.org/?p=burette%2Feturecup.git;a=blobdiff_plain;f=eturecup.py;h=0b934ed1688e65234934cc83e2b4ba075fd1fa24;hp=bdf45593df496206c78266e0756c1e72e323282b;hb=HEAD;hpb=66b1e2e6b3e02c1fee03956f328611d1d6fcd07f
diff --git a/eturecup.py b/eturecup.py
index bdf4559..0b934ed 100644
--- a/eturecup.py
+++ b/eturecup.py
@@ -2,7 +2,7 @@
##############################################################################
#
# eturecup module for OpenERP, Custom module for Ãtu'Récup
-# Copyright (C) 2014-2015 Ãtu'Récup ()
+# Copyright (C) 2014-2017 Ãtu'Récup ()
#
# This file is a part of eturecup
#
@@ -28,15 +28,61 @@ from openerp.osv import fields
class Partner(orm.Model):
_inherit = 'res.partner'
+ def _get_bikecoop_theme_type(self, cr, uid, ids, name, args, context=None):
+ """Return themes type for selected partners"""
+ res = {}
+ partners = self.browse(cr, uid, ids, context=context)
+ for partner in partners:
+ res[partner.id] = False
+ if partner.occupation_id.type == 'studies':
+ res[partner.id] = True
+ return res
+
+ def onchange_occupation_id(self, cr, uid, ids, occupation_id):
+ """Define if a partner is a student based on his/her occupation type"""
+ v = {}
+ partners = self.browse(cr, uid, ids)
+ occupations = self.pool.get('bikecoop.partner.theme')
+ occupation = occupations.browse(cr, uid, occupation_id)
+ if occupation.type == 'studies':
+ v['is_student'] = True
+ else:
+ v['is_student'] = False
+ v['is_scholarship'] = False
+
+ return {'value': v}
+
_columns = {
'newsletter': fields.boolean(
'Do you want to receive our monthly newsletter?'),
+ 'is_student': fields.function(_get_bikecoop_theme_type,
+ method=True,
+ string='Student?',
+ type='boolean',
+ store=True),
+ 'is_scholarship': fields.boolean('Scholarship',
+ help='Is this student a scholarship?'),
'want_to_be_volunteer': fields.boolean(
'Do you want to receive some informations about volunteer \
activities?',
help='⦠in company and its activities: bikecoop, events, â¦'),
}
+ def _check_occupation_is_not_studies(self, cr, uid, ids, context=None):
+ """Check if partners are students. If not, they can't be
+ scholarships."""
+ partners = self.browse(cr, uid, ids, context=context)
+ for partner in partners:
+ if partner.occupation_id.type != 'studies':
+ if partner.is_scholarship:
+ return False
+ return True
+
+ _constraints = [
+ (_check_occupation_is_not_studies, 'Error: This partner can\'t be a\
+ scholarship because s·he isn\'t a student.', ['is_scholarship']),
+ ]
+
class Theme(orm.Model):
_inherit = 'bikecoop.partner.theme'