|
|
@ -1,4 +1,3 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
from datetime import datetime |
|
|
|
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as OE_DFORMAT |
|
|
|
|
|
|
@ -11,8 +10,10 @@ class ResPartner(models.Model): |
|
|
|
def _search_age(self, operator, value): |
|
|
|
if operator not in ('=', '!=', '<', '<=', '>', '>=', 'in', 'not in'): |
|
|
|
return [] |
|
|
|
# retrieve all the messages that match with a specific SQL query |
|
|
|
query = """SELECT id FROM "%s" WHERE extract(year from age(CURRENT_DATE, birthdate_date)) %s %%s""" % \ |
|
|
|
query = """SELECT id |
|
|
|
FROM "%s" |
|
|
|
WHERE extract(year from age(CURRENT_DATE, |
|
|
|
birthdate_date)) %s %%s""" % \ |
|
|
|
(self._table, operator) |
|
|
|
self.env.cr.execute(query, (value,)) |
|
|
|
ids = [t[0] for t in self.env.cr.fetchall()] |
|
|
@ -22,7 +23,8 @@ class ResPartner(models.Model): |
|
|
|
@api.depends('birthdate_date') |
|
|
|
def _compute_age(self): |
|
|
|
if self.birthdate_date: |
|
|
|
dBday = datetime.strptime(self.birthdate_date, OE_DFORMAT).date() |
|
|
|
dBday = datetime.strptime(str(self.birthdate_date), |
|
|
|
OE_DFORMAT).date() |
|
|
|
dToday = datetime.now().date() |
|
|
|
self.age = dToday.year - dBday.year - (( |
|
|
|
dToday.month, dToday.day) < (dBday.month, dBday.day)) |
|
|
|