Skip to content

Commit

Permalink
Merge 3488398 into 8734eab
Browse files Browse the repository at this point in the history
  • Loading branch information
bjeficent committed Mar 19, 2019
2 parents 8734eab + 3488398 commit 7461def
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions sales_team_operating_unit/models/crm_team.py
Expand Up @@ -5,7 +5,7 @@
# (<http://www.serpentcs.com>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError


class CrmTeam(models.Model):
Expand All @@ -24,5 +24,15 @@ def _check_company_operating_unit(self):
if team.company_id and \
team.operating_unit_id and \
team.company_id != team.operating_unit_id.company_id:
raise UserError(_('Configuration error!\n\nThe Company in the\
raise UserError(_('Configuration error\n\nThe Company in the\
Sales Team and in the Operating Unit must be the same.'))

@api.multi
@api.constrains('operating_unit_id', 'member_ids')
def _check_member_operating_unit(self):
for rec in self.member_ids:
if (rec and self.operating_unit_id and
self.operating_unit_id not in rec.operating_unit_ids):
raise ValidationError(_('Configuration error. The user %s '
'has not assigned the same '
'Operating unit.' % rec.name))
12 changes: 11 additions & 1 deletion sales_team_operating_unit/tests/test_crm_team_operating_unit.py
Expand Up @@ -5,7 +5,7 @@
# (<http://www.serpentcs.com>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.tests import common

from odoo import exceptions

class TestSaleTeamOperatingUnit(common.TransactionCase):

Expand Down Expand Up @@ -65,3 +65,13 @@ def test_crm_team(self):
('operating_unit_id', '=', self.ou1.id)])
self.assertEqual(team.ids, [], 'User 2 should not have access to '
'%s' % self.ou1.name)

def test_member_operating_unit(self):
# User 2 is assigned to B2C Operating Unit and cannot be a member of
# a team with the Operating Unit OU1
with self.assertRaises(exceptions.ValidationError):
self.crm_team_model.sudo().create({
'name': 'Test Team',
'operating_unit_id': self.ou1.id,
'member_ids': [(4, self.user2.id)]
})

0 comments on commit 7461def

Please sign in to comment.