From 301f88f5372c0c138c45e98fdc08bd25b41d8f6d Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Thu, 14 Jan 2021 15:14:10 +0100 Subject: [PATCH] [IMP]GOLEM Member : allow more operators on search age --- golem_member/__manifest__.py | 4 ++-- golem_member/models/golem_member.py | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/golem_member/__manifest__.py b/golem_member/__manifest__.py index 2b02730..f4224b4 100644 --- a/golem_member/__manifest__.py +++ b/golem_member/__manifest__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2016-2020 Fabien Bourgeois +# Copyright 2016-2021 Fabien Bourgeois # Copyright 2018 Michel Dessenne # Copyright 2018 Youssef El Ouahby @@ -21,7 +21,7 @@ 'name': 'GOLEM non-profit members', 'summary': 'Extends Odoo contacts for MJC', 'description': 'Extends Odoo contacts for MJC', - 'version': '10.0.2.8.2', + 'version': '10.0.2.8.3', 'category': 'GOLEM', 'author': 'Fabien Bourgeois, Michel Dessenne', 'license': 'AGPL-3', diff --git a/golem_member/models/golem_member.py b/golem_member/models/golem_member.py index 46714f8..30fce6c 100644 --- a/golem_member/models/golem_member.py +++ b/golem_member/models/golem_member.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright 2016-2019 Fabien Bourgeois +# Copyright 2016-2021 Fabien Bourgeois # Copyright 2018 Youssef El Ouahby # # This program is free software: you can redistribute it and/or modify @@ -103,14 +103,30 @@ class ResPartner(models.Model): def _search_age(self, operator, value): """ Age search function """ - if operator != '=': + if operator not in ('=', '!=', '<', '<=', '>', '>='): err = _('Unsupported operator for age search') raise NotImplementedError(err) today = date.today() - min_birthdate_date = today - timedelta(days=365.25 * value) - max_birthdate_date = today - timedelta(days=365.25 * (value + 1)) - return ['&', ('birthdate_date', '>', max_birthdate_date), - ('birthdate_date', '<=', min_birthdate_date)] + birthdate_date = today - timedelta(days=365.25 * value) + if operator in ('=', '!='): + birthdate_date = today - timedelta(days=365.25 * value) + max_birthdate_date = today - timedelta(days=365.25 * (value + 1)) + if operator == '=': + return ['&', ('birthdate_date', '>', max_birthdate_date), + ('birthdate_date', '<=', birthdate_date)] + else: + return ['|', ('birthdate_date', '<=', max_birthdate_date), + ('birthdate_date', '>', birthdate_date)] + else: + if operator == '>': + operator = '<' + elif operator == '>=': + operator = '<=' + elif operator == '<': + operator = '>' + else: + operator = '>=' + return [('birthdate_date', operator, birthdate_date)] @api.model def _get_default_nationality_id(self):