2016-06-25 18:08:01 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-08-26 18:16:50 +02:00
|
|
|
# Copyright 2017-2018 Fabien Bourgeois <fabien@yaltik.com>
|
2016-06-25 18:08:01 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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 Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-05-01 22:15:39 +02:00
|
|
|
""" GOLEM Member Minor management """
|
|
|
|
|
2018-08-26 18:16:50 +02:00
|
|
|
from datetime import date, timedelta
|
2017-04-29 09:16:41 +02:00
|
|
|
from odoo import models, fields, api
|
2016-06-25 18:08:01 +02:00
|
|
|
|
2018-08-26 18:16:50 +02:00
|
|
|
ADULT_DURATION = timedelta(days=365.25*18)
|
|
|
|
|
2016-06-25 18:08:01 +02:00
|
|
|
class GolemMember(models.Model):
|
2017-05-01 22:15:39 +02:00
|
|
|
""" GOLEM Member adaptations """
|
2016-06-25 18:08:01 +02:00
|
|
|
_inherit = 'golem.member'
|
|
|
|
|
2018-10-02 00:55:02 +02:00
|
|
|
legal_guardian_ids = fields.One2many('golem.legal.guardian', 'member_id',
|
|
|
|
string='Legal guardians')
|
2016-06-25 18:08:01 +02:00
|
|
|
activities_participation = fields.Boolean('Activities participation?')
|
2018-08-26 18:16:50 +02:00
|
|
|
leave_alone = fields.Boolean('Can leave alone?')
|
2016-06-25 18:08:01 +02:00
|
|
|
is_minor = fields.Boolean('Is minor?', compute='_compute_is_minor',
|
2018-08-26 18:16:50 +02:00
|
|
|
search='_search_is_minor', default=False)
|
2016-06-25 18:08:01 +02:00
|
|
|
|
|
|
|
@api.depends('birthdate_date')
|
|
|
|
def _compute_is_minor(self):
|
2017-05-01 22:15:39 +02:00
|
|
|
for member in self:
|
|
|
|
if member.birthdate_date:
|
2018-08-26 18:16:50 +02:00
|
|
|
member.is_minor = ((date.today() - ADULT_DURATION) <
|
|
|
|
fields.Date.from_string(member.birthdate_date))
|
2017-05-01 22:15:39 +02:00
|
|
|
else:
|
|
|
|
member.is_minor = False
|
2018-08-26 18:16:50 +02:00
|
|
|
|
|
|
|
def _search_is_minor(self, operator, value):
|
|
|
|
""" Search function for is minor """
|
|
|
|
today = date.today()
|
|
|
|
adult_date = today - ADULT_DURATION
|
|
|
|
if operator == '=':
|
|
|
|
operator = '>' if value else '<='
|
|
|
|
else:
|
|
|
|
operator = '<=' if value else '>'
|
|
|
|
return [('birthdate_date', operator, adult_date)]
|