[PYTHON][VIEW] +eturecup functionnalities
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Fri, 12 Oct 2018 07:32:41 +0000 (09:32 +0200)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Fri, 12 Oct 2018 07:32:41 +0000 (09:32 +0200)
__init__.py
__openerp__.py
data/base.xml
letriseratop.py [new file with mode: 0644]
view/bikecoop.xml [new file with mode: 0644]

index a69a64a..11b65d4 100644 (file)
@@ -21,4 +21,6 @@
 #
 ##############################################################################
 
+import letriseratop
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
index b16ce11..e712856 100644 (file)
@@ -42,6 +42,7 @@ It installs the profile for bike co-ops to manage some features like:
     ],
     'update_xml': [
         'data/base.xml',
+        'view/bikecoop.xml',
     ],
     'installable': True,
     'auto_install': False,
index 354cb4a..2cbf7f4 100644 (file)
@@ -16,9 +16,9 @@
             <field name="name">Le Tri Sera Top</field>
             <field name="partner_id" ref="base.main_partner"/>
             <field name="rml_header1"></field>
-            <field name="rml_footer">N° SIRET : XXXXXXXXX XXXXX - Code NAF : YYYYZ</field>
-            <field name="siret">XXXXXXXXX XXXXX</field>
-            <field name="ape">YYYYZ</field>
+            <field name="rml_footer">N° SIRET : 828436519 00015 - Code NAF : 9499Z</field>
+            <field name="siret">828436519 00015</field>
+            <field name="ape">9499Z</field>
             <field name="currency_id" ref="base.EUR"/>
         </record>
     </data>
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:
diff --git a/view/bikecoop.xml b/view/bikecoop.xml
new file mode 100644 (file)
index 0000000..953aeb1
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="view_themes_form" model="ir.ui.view">
+            <field name="name">bikecoop.partner.theme.form</field>
+            <field name="model">bikecoop.partner.theme</field>
+            <field name="inherit_id" ref="bikecoop.view_themes_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='code']" position="before">
+                    <field name="type"/>
+                    <newline/>
+                </xpath>
+            </field>
+        </record>
+        <record id="view_bikecoop_l10n_fr_members_form" model="ir.ui.view">
+            <field name="name">res.partner.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="bikecoop_l10n_fr.view_bikecoop_l10n_fr_members_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//page[@string='Memberships']" position="after">
+                    <page string="Invoice membership" groups="base.group_user">
+                        <p>This is a special functionnality for Le Tri Sera Top that doesn't use the point of sale at moment. It's not a permanent functionnality.</p>
+                        <button name="%(membership.action_membership_invoice_view)d" type="action" string="Join membership"/>
+                    </page>
+                </xpath>
+            </field>
+        </record>
+        <record id="view_bikecoop_members_form" model="ir.ui.view">
+            <field name="name">res.partner.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="bikecoop.view_bikecoop_members_form"/>
+            <field name="priority" eval="8"/>
+            <field name="arch" type="xml">
+                <xpath expr="//notebook[@name='Volunteer activities']" position="replace">
+                    <group colspan="4">
+                        <field name="newsletter"/>
+                        <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="is_scholarship" attrs="{'invisible': [('is_student','=', False)]}"/>
+                </xpath>
+            </field>
+        </record>
+            
+    </data>
+</openerp>