From 8cac769c165bdc0290f42317928297698175819e Mon Sep 17 00:00:00 2001 From: Ludovic CHEVALIER Date: Fri, 12 Oct 2018 09:32:41 +0200 Subject: [PATCH] [PYTHON][VIEW] +eturecup functionnalities --- __init__.py | 2 + __openerp__.py | 1 + data/base.xml | 6 +-- letriseratop.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++ view/bikecoop.xml | 49 ++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 letriseratop.py create mode 100644 view/bikecoop.xml diff --git a/__init__.py b/__init__.py index a69a64a..11b65d4 100644 --- a/__init__.py +++ b/__init__.py @@ -21,4 +21,6 @@ # ############################################################################## +import letriseratop + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/__openerp__.py b/__openerp__.py index b16ce11..e712856 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -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, diff --git a/data/base.xml b/data/base.xml index 354cb4a..2cbf7f4 100644 --- a/data/base.xml +++ b/data/base.xml @@ -16,9 +16,9 @@ Le Tri Sera Top - N° SIRET : XXXXXXXXX XXXXX - Code NAF : YYYYZ - XXXXXXXXX XXXXX - YYYYZ + N° SIRET : 828436519 00015 - Code NAF : 9499Z + 828436519 00015 + 9499Z diff --git a/letriseratop.py b/letriseratop.py new file mode 100644 index 0000000..d4abae6 --- /dev/null +++ b/letriseratop.py @@ -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 . +# +############################################################################## + +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 index 0000000..953aeb1 --- /dev/null +++ b/view/bikecoop.xml @@ -0,0 +1,49 @@ + + + + + bikecoop.partner.theme.form + bikecoop.partner.theme + + + + + + + + + + res.partner.form + res.partner + + + + +

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.

+