2017-11-03 15:28:45 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
""" Coworker module """
|
|
|
|
|
2017-11-06 15:54:17 +01:00
|
|
|
from odoo import models, fields, api, _
|
|
|
|
from odoo.exceptions import ValidationError
|
2017-11-03 15:28:45 +01:00
|
|
|
|
|
|
|
class Coworker(models.Model):
|
|
|
|
""" Coworker model """
|
|
|
|
_name = 'coworking.coworker'
|
|
|
|
_description = 'Coworker model definition'
|
2017-11-06 14:35:02 +01:00
|
|
|
_order = 'id desc'
|
2017-11-03 15:28:45 +01:00
|
|
|
|
2017-11-09 10:02:21 +01:00
|
|
|
contact_date = fields.Date(default=fields.Date.context_today)
|
2017-11-07 12:13:35 +01:00
|
|
|
|
2017-11-09 10:02:21 +01:00
|
|
|
full_name = fields.Char(compute='_compute_full_name', store=True, index=True)
|
2017-11-03 15:28:45 +01:00
|
|
|
firstname = fields.Char('First name', required=True)
|
2017-11-09 10:02:21 +01:00
|
|
|
|
2017-11-03 15:28:45 +01:00
|
|
|
coworker_type = fields.Selection([('staffer', 'Staffer'),
|
|
|
|
('worker', 'Worker'), ('member', 'Member'),
|
|
|
|
('volunteer', 'Volunteer'),
|
|
|
|
('visitor', 'Visitor')])
|
|
|
|
company_name = fields.Char('Company')
|
|
|
|
job = fields.Char()
|
2017-11-07 17:55:42 +01:00
|
|
|
|
|
|
|
#Adress fields
|
2017-11-03 15:28:45 +01:00
|
|
|
street = fields.Char()
|
2017-11-06 15:54:17 +01:00
|
|
|
contact_zip = fields.Char()
|
2017-11-03 15:28:45 +01:00
|
|
|
city = fields.Char()
|
2017-11-07 12:13:35 +01:00
|
|
|
full_contact_adress = fields.Char(compute='_compute_full_contact_adress')
|
2017-11-07 17:55:42 +01:00
|
|
|
|
2017-11-03 15:28:45 +01:00
|
|
|
phone_number = fields.Char()
|
|
|
|
gsm = fields.Char('GSM')
|
|
|
|
email = fields.Char()
|
|
|
|
url = fields.Char('URL')
|
|
|
|
note = fields.Text()
|
|
|
|
|
2017-11-09 10:02:21 +01:00
|
|
|
#Images fields
|
2017-11-07 17:55:42 +01:00
|
|
|
contact_image = fields.Binary()
|
|
|
|
|
2017-11-03 15:28:45 +01:00
|
|
|
is_done = fields.Boolean('Done?')
|
|
|
|
is_active = fields.Boolean('Active?', default=True)
|
2017-11-06 15:54:17 +01:00
|
|
|
|
2017-11-06 22:48:27 +01:00
|
|
|
@api.depends('name', 'firstname')
|
|
|
|
def _compute_full_name(self):
|
2017-11-07 17:00:49 +01:00
|
|
|
"""Concaténation du nom et du prénom"""
|
2017-11-06 22:48:27 +01:00
|
|
|
for coworker in self:
|
|
|
|
coworker.full_name = u'{} {}'.format(coworker.name, coworker.firstname)
|
|
|
|
|
2017-11-06 15:54:17 +01:00
|
|
|
@api.constrains('contact_date')
|
|
|
|
def _check_contact_date(self):
|
2017-11-07 17:00:49 +01:00
|
|
|
"""Test si la modification de la date n'est pas superieur à la date du jour"""
|
2017-11-06 15:54:17 +01:00
|
|
|
if self.contact_date > fields.Date.context_today(self):
|
2017-11-07 12:13:35 +01:00
|
|
|
raise ValidationError(_('Date most be equal of inferior to to day'))
|
2017-11-06 22:48:27 +01:00
|
|
|
|
|
|
|
@api.constrains('company_name', 'job')
|
|
|
|
def _check_company_name(self):
|
|
|
|
for coworker in self:
|
2017-11-07 17:00:49 +01:00
|
|
|
"""Contrainte python sur company_name et job,
|
|
|
|
si il y a une raison sociale le champ job est à remplir
|
|
|
|
"""
|
2017-11-06 22:48:27 +01:00
|
|
|
if coworker.company_name and not coworker.job:
|
|
|
|
raise ValidationError(_('You must enter job and compagny both'))
|
2017-11-07 12:13:35 +01:00
|
|
|
|
|
|
|
@api.depends('street', 'contact_zip', 'city')
|
|
|
|
def _compute_full_contact_adress(self):
|
2017-11-07 17:00:49 +01:00
|
|
|
"""Concatènation de l'adresse si les chanps street, contact-zip et city sont renseignés"""
|
2017-11-07 12:13:35 +01:00
|
|
|
for coworker in self:
|
2017-11-07 17:00:49 +01:00
|
|
|
coworker.full_contact_adress = u'{} {} {}'.format \
|
|
|
|
(coworker.street or u'', coworker.contact_zip or u'', coworker.city or u'').strip()
|