Skip to content

Commit 3b585e5

Browse files
committed
[IMP] Relate crm.team.member company_id to crm.team not res.users
This allows users to be members of sales teams across multiple companies simultaneously.
1 parent 4e51a4a commit 3b585e5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

addons/sales_team/models/crm_team_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CrmTeamMember(models.Model):
3939
email = fields.Char(string='Email', related='user_id.email')
4040
phone = fields.Char(string='Phone', related='user_id.phone')
4141
mobile = fields.Char(string='Mobile', related='user_id.mobile')
42-
company_id = fields.Many2one('res.company', string='Company', related='user_id.company_id')
42+
company_id = fields.Many2one('res.company', string='Company', related='crm_team_id.company_id', store=True)
4343

4444
@api.constrains('crm_team_id', 'user_id', 'active')
4545
def _constrains_membership(self):

addons/sales_team/tests/test_sales_team.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def test_team_members(self):
176176
self.assertEqual(team_c2.member_ids, self.user_sales_salesman)
177177

178178
# cannot change team company if its users aren't allowed in the new company
179-
with self.assertRaises(exceptions.UserError):
180-
team_c2.write({'company_id': self.company_2.id})
179+
# HACK not anymore
180+
# with self.assertRaises(exceptions.UserError):
181+
# team_c2.write({'company_id': self.company_2.id})
181182

182183
# a user allowed in multiple companies can be added to a team of any of these companies
183184
team_c2.write({'member_ids': [(5, 0)]})
@@ -217,8 +218,9 @@ def test_team_memberships(self):
217218
self.assertEqual(team_c2.member_ids, self.user_sales_salesman)
218219

219220
# cannot change company as it breaks memberships mc check
220-
with self.assertRaises(exceptions.UserError):
221-
team_c2.write({'company_id': self.company_2.id})
221+
# HACK not anymore
222+
# with self.assertRaises(exceptions.UserError):
223+
# team_c2.write({'company_id': self.company_2.id})
222224

223225

224226
@tagged('post_install', '-at_install')

0 commit comments

Comments
 (0)