54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
# -*- 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'
|
|
|
|
is_coworker = fields.Boolean('Coworker', default=False)
|
|
# coworker_count = fields.Integer('Number of coworker',
|
|
# compute='_compute_coworker_count')
|
|
|
|
|
|
company_ids = fields.One2many(
|
|
string="Company",
|
|
comodel_name="res.partner",
|
|
inverse_name="parent_id",
|
|
)
|
|
|
|
url = fields.Char('URL')
|
|
|
|
contact_date = fields.Date(default=fields.Date.context_today)
|
|
|
|
coworker_type = fields.Selection([('staffer', 'Staffer'),
|
|
('worker', 'Worker'), ('member', 'Member'),
|
|
('volunteer', 'Volunteer'),
|
|
('visitor', 'Visitor')])
|
|
|
|
full_contact_adress = fields.Char(compute='_compute_full_contact_adress')
|
|
|
|
@api.depends('is_coworker')
|
|
def _compute_coworker_count(self):
|
|
""" Computes number of coworker """
|
|
for res_partner in self:
|
|
if self.is_coworker():
|
|
self.coworker_count = len(self.is_coworker)
|
|
|
|
@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()
|
|
|
|
|
|
@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'))
|