Browse Source

[IMP] calculate age field upon birthdate_date field from

partner_birthdate.
pull/1/head
houssine 7 years ago
parent
commit
3a99c10928
  1. 4
      partner_age/__openerp__.py
  2. 8
      partner_age/models/partner.py

4
partner_age/__openerp__.py

@ -21,7 +21,9 @@
{
"name": "Partner Age",
"version": "1.0",
"depends": ["easy_my_coop"],
"depends": [
"easy_my_coop",
"partner_contact_birthdate"],
"author": "Houssine BAKKALI <houssine.bakkali@gmail.com>",
"category": "Cooperative management",
'website': "www.coopiteasy.be",

8
partner_age/models/partner.py

@ -11,17 +11,17 @@ class ResPartner(models.Model):
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)) %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()]
return [('id', 'in', ids)]
@api.one
@api.depends('birthdate')
@api.depends('birthdate_date')
def _compute_age(self):
if self.birthdate:
dBday = datetime.strptime(self.birthdate, OE_DFORMAT).date()
if self.birthdate_date:
dBday = datetime.strptime(self.birthdate_date, OE_DFORMAT).date()
dToday = datetime.now().date()
self.age = dToday.year - dBday.year - ((
dToday.month, dToday.day) < (dBday.month, dBday.day))

Loading…
Cancel
Save