2017-11-24 10:05:18 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
""" Coworker module """
|
|
|
|
|
|
|
|
from odoo import models, fields, api, _
|
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
|
|
""" Coworker model """
|
|
|
|
_inherit = 'res.partner'
|
2017-11-24 16:25:14 +01:00
|
|
|
|
2017-11-28 12:29:13 +01:00
|
|
|
is_coworker = fields.Boolean('Coworker', default=False)
|
2017-11-24 10:05:18 +01:00
|
|
|
company_ids = fields.One2many(
|
|
|
|
string="Company",
|
|
|
|
comodel_name="res.partner",
|
|
|
|
inverse_name="parent_id",
|
|
|
|
)
|
|
|
|
|
2017-11-24 17:16:20 +01:00
|
|
|
url = fields.Char('URL')
|
2017-11-24 16:25:14 +01:00
|
|
|
|
|
|
|
contact_date = fields.Date(default=fields.Date.context_today)
|
|
|
|
|
|
|
|
coworker_type = fields.Selection([('staffer', 'Staffer'),
|
|
|
|
('worker', 'Worker'), ('member', 'Member'),
|
|
|
|
('volunteer', 'Volunteer'),
|
|
|
|
('visitor', 'Visitor')])
|
|
|
|
|
2017-11-27 16:02:09 +01:00
|
|
|
full_contact_adress = fields.Char(compute='_compute_full_contact_adress')
|
|
|
|
|
|
|
|
@api.depends('street', 'zip', 'city')
|
|
|
|
def _compute_full_contact_adress(self):
|
|
|
|
"""Concatènation de l'adresse si les chanps street, czip et city sont renseignés"""
|
|
|
|
for coworker in self:
|
|
|
|
coworker.full_contact_adress = u'{} {} {}'.format \
|
|
|
|
(coworker.street or u'', coworker.zip or u'', coworker.city or u'').strip()
|
|
|
|
|
2017-11-24 16:25:14 +01:00
|
|
|
@api.constrains('contact_date')
|
|
|
|
def _check_contact_date(self):
|
|
|
|
"""Test si la modification de la date n'est pas superieur à la date du jour"""
|
|
|
|
if self.contact_date > fields.Date.context_today(self):
|
|
|
|
raise ValidationError(_('Date most be equal of inferior to to day'))
|
2017-11-28 17:15:18 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _manage_coworker_type(vals):
|
|
|
|
""" Ensures that coworker_type is not defined when is_coworker is False """
|
|
|
|
if 'is_coworker' in vals:
|
|
|
|
if not vals['is_coworker']:
|
|
|
|
vals.update({'coworker_type': False})
|
|
|
|
return vals
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def create(self, vals):
|
|
|
|
""" Ensures that coworker_type is not defined when is_coworker is False """
|
|
|
|
vals = ResPartner._manage_coworker_type(vals)
|
|
|
|
return super(ResPartner, self).create(vals)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def write(self, vals):
|
|
|
|
""" Ensures that coworker_type is not defined when is_coworker is False """
|
|
|
|
vals = ResPartner._manage_coworker_type(vals)
|
|
|
|
super(ResPartner, self).write(vals)
|
|
|
|
return True
|