From e37774fff6801e3e8c2f681bdc5e4b82613aa6bb Mon Sep 17 00:00:00 2001 From: michel Date: Thu, 16 Nov 2017 16:48:32 +0100 Subject: [PATCH] Test coworker1 coworker2 is same --- coworking_relation/models/relation.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/coworking_relation/models/relation.py b/coworking_relation/models/relation.py index fc78b8f..99d167a 100644 --- a/coworking_relation/models/relation.py +++ b/coworking_relation/models/relation.py @@ -2,7 +2,9 @@ """ Coworker relation """ -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + class CoworkerRelation(models.Model): """Coworker relation model """ @@ -13,11 +15,18 @@ class CoworkerRelation(models.Model): name = fields.Char() coworker1 = fields.Many2one( - 'coworking.coworker', 'Coworker1', index=True, required=True, + 'coworking.coworker', 'Coworker 1', index=True, required=True, domain="[('coworker_type', 'in', ['staffer', 'member', 'worker', 'volunteer', 'visitor'])]" ) coworker2 = fields.Many2one( - 'coworking.coworker', 'Coworker2', index=True, required=True, + 'coworking.coworker', 'Coworker 2', index=True, required=True, domain="[('coworker_type', 'in', ['staffer', 'member', 'worker', 'volunteer', 'visitor'])]" ) relation = fields.Char(index=True, required=True) + + + @api.constrains('coworker1', 'coworker2') + def _check_if_coworker_is_same(self): + """Test si coworker1 est identique à coworker2""" + if not self.coworker1 != self.coworker2: + raise ValidationError(_('Coworker1 is same coworker2'))