You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
835 B

  1. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  2. # Copyright 2017-Apertoso N.V. (<http://www.apertoso.be>)
  3. # Copyright 2019-2020: Druidoo (<https://www.druidoo.io>)
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from dateutil.relativedelta import relativedelta
  6. from odoo import api, fields, models
  7. class ResPartner(models.Model):
  8. """Partner with birth date in date format."""
  9. _inherit = "res.partner"
  10. birthdate_date = fields.Date("Birthdate")
  11. age = fields.Integer(string="Age", readonly=True, compute="_compute_age")
  12. @api.depends("birthdate_date")
  13. def _compute_age(self):
  14. for record in self:
  15. age = 0
  16. if record.birthdate_date:
  17. age = relativedelta(fields.Date.today(), record.birthdate_date).years
  18. record.age = age