forked from michel/Coworking
Full name
This commit is contained in:
parent
80c7a95bc4
commit
eca14eb74d
@ -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'))
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
<odoo>
|
||||
|
||||
<record id="view_form_coworker" model="ir.ui.view">
|
||||
<field name="name">Coworker Form</field>
|
||||
@ -11,12 +11,13 @@
|
||||
<group name="group_top">
|
||||
<group name="group_left">
|
||||
<field name="contact_date" />
|
||||
<field name="full_name" />
|
||||
<field name="name" />
|
||||
<field name="firstname" />
|
||||
<field name="coworker_type" />
|
||||
<field name="company_name" />
|
||||
<field name="job"
|
||||
attrs="{'invisible': [('company_name', '=', False)], 'required': [('company_name', '!=', False)]}" />
|
||||
<field name="job" />
|
||||
<!-- attrs="{'invisible': [('company_name', '=', False)], 'required': [('company_name', '!=', False)]}" -->
|
||||
</group>
|
||||
<group name="group_right">
|
||||
<field name="street" />
|
||||
|
Loading…
Reference in New Issue
Block a user