[MODULE][VIEW] +is_student and scholarship in member form
authorLudovic CHEVALIER <ludovic@beurresarrasin.net>
Thu, 2 Nov 2017 17:46:23 +0000 (18:46 +0100)
committerLudovic CHEVALIER <ludovic@beurresarrasin.net>
Thu, 2 Nov 2017 17:46:23 +0000 (18:46 +0100)
eturecup.py
view/bikecoop.xml

index bdf4559..14a3298 100644 (file)
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    eturecup module for OpenERP, Custom module for Étu'Récup
-#    Copyright (C) 2014-2015 Étu'Récup (<http://www.eturecup.org/>)
+#    Copyright (C) 2014-2017 Étu'Récup (<http://www.eturecup.org/>)
 #
 #    This file is a part of eturecup
 #
@@ -28,9 +28,38 @@ 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')
+        for partner in partners:
+            v['is_student'] = False
+            occupation = occupations.browse(cr, uid, occupation_id)
+            if occupation.type == 'studies':
+                v['is_student'] = True
+        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='Is this partner a student?',
+                                      type='boolean',
+                                      store=True),
+        '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?',
index 6d7598c..558ba6b 100644 (file)
                         <field name="want_to_be_volunteer"/>
                     </group>
                 </xpath>
+                <xpath expr="//field[@name='occupation_id']" position="replace">
+                    <field name="occupation_id" on_change="onchange_occupation_id(occupation_id)" domain="[('domain','=', 'occupation')]" attrs="{'required': [('is_company','=', False)]}" widget="selection"/>
+                    <field name="is_student"/>
+                    <field name="scholarship" attrs="{'invisible': [('is_student','=', False)]}"/>
+                </xpath>
             </field>
         </record>