forked from michel/Coworking
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
""" Coworker module """
|
|
|
|
from odoo import models, fields, api, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
class Coworker(models.Model):
|
|
""" Coworker model """
|
|
_name = 'coworking.coworker'
|
|
_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'),
|
|
('worker', 'Worker'), ('member', 'Member'),
|
|
('volunteer', 'Volunteer'),
|
|
('visitor', 'Visitor')])
|
|
company_name = fields.Char('Company')
|
|
job = fields.Char()
|
|
contact_date = fields.Date(default=fields.Date.context_today)
|
|
street = fields.Char()
|
|
contact_zip = fields.Char()
|
|
city = fields.Char()
|
|
phone_number = fields.Char()
|
|
gsm = fields.Char('GSM')
|
|
email = fields.Char()
|
|
url = fields.Char('URL')
|
|
note = fields.Text()
|
|
|
|
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'))
|