From eca14eb74d5c40b57ee9c97160803f1bf34ad4e6 Mon Sep 17 00:00:00 2001 From: michel Date: Mon, 6 Nov 2017 22:48:27 +0100 Subject: [PATCH] Full name --- models/coworker.py | 12 ++++++++++++ views/coworker_views.xml | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/models/coworker.py b/models/coworker.py index 713c4ee..621caad 100644 --- a/models/coworker.py +++ b/models/coworker.py @@ -11,6 +11,7 @@ class Coworker(models.Model): _description = 'Coworker model definition' _order = 'id desc' + full_name = fields.Char(compute='_compute_full_name', store=True, index=True) name = fields.Char(required=True) firstname = fields.Char('First name', required=True) coworker_type = fields.Selection([('staffer', 'Staffer'), @@ -32,8 +33,19 @@ class Coworker(models.Model): is_done = fields.Boolean('Done?') is_active = fields.Boolean('Active?', default=True) + @api.depends('name', 'firstname') + def _compute_full_name(self): + for coworker in self: + coworker.full_name = u'{} {}'.format(coworker.name, coworker.firstname) + @api.constrains('contact_date') def _check_contact_date(self): if self.contact_date > fields.Date.context_today(self): raise ValidationError(_('Date most be egual of inferior to to day')) + + @api.constrains('company_name', 'job') + def _check_company_name(self): + for coworker in self: + if coworker.company_name and not coworker.job: + raise ValidationError(_('You must enter job and compagny both')) diff --git a/views/coworker_views.xml b/views/coworker_views.xml index d45aa8c..561ec35 100644 --- a/views/coworker_views.xml +++ b/views/coworker_views.xml @@ -1,6 +1,6 @@ - + Coworker Form @@ -11,12 +11,13 @@ + - + +