[IMP]GOLEM Member : allow more operators on search age

This commit is contained in:
Fabien BOURGEOIS 2021-01-14 15:14:10 +01:00
parent f695e36811
commit 301f88f537
2 changed files with 24 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2020 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2016-2021 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2018 Michel Dessenne <michel@yaltik.com>
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
@ -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',

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright 2016-2019 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2016-2021 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
#
# 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):