Coworking/coworking_relation/models/relation.py

33 lines
1.1 KiB
Python
Raw Normal View History

2017-11-16 15:47:18 +01:00
# -*- coding: utf-8 -*-
""" Coworker relation """
2017-11-16 16:48:32 +01:00
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
2017-11-16 15:47:18 +01:00
class CoworkerRelation(models.Model):
"""Coworker relation model """
_name = 'coworking.relation'
_description = 'relation model definition'
_order = 'id asc'
2017-11-16 16:02:30 +01:00
name = fields.Char()
coworker1 = fields.Many2one(
2017-11-16 16:48:32 +01:00
'coworking.coworker', 'Coworker 1', index=True, required=True,
domain="[('coworker_type', 'in', ['staffer', 'member', 'worker', 'volunteer', 'visitor'])]"
)
coworker2 = fields.Many2one(
2017-11-16 16:48:32 +01:00
'coworking.coworker', 'Coworker 2', index=True, required=True,
domain="[('coworker_type', 'in', ['staffer', 'member', 'worker', 'volunteer', 'visitor'])]"
)
relation = fields.Char(index=True, required=True)
2017-11-16 16:48:32 +01:00
@api.constrains('coworker1', 'coworker2')
def _check_if_coworker_is_same(self):
"""Test si coworker1 est identique à coworker2"""
2017-11-16 16:59:02 +01:00
if self.coworker1 == self.coworker2:
2017-11-16 16:48:32 +01:00
raise ValidationError(_('Coworker1 is same coworker2'))