[PYTHON][VIEW] +eturecup functionnalities
[burette/letriseratop.git] / letriseratop.py
diff --git a/letriseratop.py b/letriseratop.py
new file mode 100644 (file)
index 0000000..d4abae6
--- /dev/null
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    letriseratop module for OpenERP, Custom module for Étu'Récup
+#    Copyright (C) 2014-2018 Le Tri Sera Top
+#
+#    This file is a part of letriseratop
+#
+#    letriseratop is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    letriseratop 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import orm
+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'
+
+    _columns = {
+        'type': fields.selection([('studies', 'Studies')],
+                                 'Type',
+                                 help='An extra field to categorize themes.'),
+    }
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: