|
@@ -20,6 +20,7 @@
|
|
|
##############################################################################
|
|
|
|
|
|
from openerp import models, fields, tools, api, _
|
|
|
+from datetime import date, datetime
|
|
|
|
|
|
class res_partner(models.Model):
|
|
|
_name = 'res.partner'
|
|
@@ -53,7 +54,18 @@ class res_partner(models.Model):
|
|
|
trab_street = fields.Char('Dirección Laboral')
|
|
|
trab_city = fields.Char('Ciudad donde trabaja')
|
|
|
ubicacion = fields.Char('Ubicación Google Map')
|
|
|
+ edad = fields.Integer('Edad', compute='_compute_edad', store=True)
|
|
|
|
|
|
+ @api.depends('fecha_nac')
|
|
|
+ def _compute_edad(self):
|
|
|
+ """ Calcula la edad basada en la fecha de nacimiento """
|
|
|
+ today = date.today()
|
|
|
+ for record in self:
|
|
|
+ if record.fecha_nac:
|
|
|
+ birth_date = fields.Date.from_string(record.fecha_nac)
|
|
|
+ record.edad = today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))
|
|
|
+ else:
|
|
|
+ record.edad = 0
|
|
|
|
|
|
_sql_constraints = [
|
|
|
('ruc_uniq', 'unique (ruc)', 'El número de R.U.C./C.I. debe ser único!')
|