michel_coworking/coworking_relation/models/relation.py

33 lines
954 B
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-28 17:15:18 +01:00
'res.partner', 'Coworker 1', index=True, required=True,
domain="[('is_coworker', '=', True)]"
)
coworker2 = fields.Many2one(
2017-11-28 17:15:18 +01:00
'res.partner', 'Coworker 2', index=True, required=True,
domain="[('is_coworker', '=', True)]"
)
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'))