Full name

This commit is contained in:
michel 2017-11-06 22:48:27 +01:00
parent 80c7a95bc4
commit eca14eb74d
2 changed files with 16 additions and 3 deletions

View File

@ -11,6 +11,7 @@ class Coworker(models.Model):
_description = 'Coworker model definition' _description = 'Coworker model definition'
_order = 'id desc' _order = 'id desc'
full_name = fields.Char(compute='_compute_full_name', store=True, index=True)
name = fields.Char(required=True) name = fields.Char(required=True)
firstname = fields.Char('First name', required=True) firstname = fields.Char('First name', required=True)
coworker_type = fields.Selection([('staffer', 'Staffer'), coworker_type = fields.Selection([('staffer', 'Staffer'),
@ -32,8 +33,19 @@ class Coworker(models.Model):
is_done = fields.Boolean('Done?') is_done = fields.Boolean('Done?')
is_active = fields.Boolean('Active?', default=True) 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') @api.constrains('contact_date')
def _check_contact_date(self): def _check_contact_date(self):
if self.contact_date > fields.Date.context_today(self): if self.contact_date > fields.Date.context_today(self):
raise ValidationError(_('Date most be egual of inferior to to day')) 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'))

View File

@ -11,12 +11,13 @@
<group name="group_top"> <group name="group_top">
<group name="group_left"> <group name="group_left">
<field name="contact_date" /> <field name="contact_date" />
<field name="full_name" />
<field name="name" /> <field name="name" />
<field name="firstname" /> <field name="firstname" />
<field name="coworker_type" /> <field name="coworker_type" />
<field name="company_name" /> <field name="company_name" />
<field name="job" <field name="job" />
attrs="{'invisible': [('company_name', '=', False)], 'required': [('company_name', '!=', False)]}" /> <!-- attrs="{'invisible': [('company_name', '=', False)], 'required': [('company_name', '!=', False)]}" -->
</group> </group>
<group name="group_right"> <group name="group_right">
<field name="street" /> <field name="street" />