[FIX] base: User loses company access when merging the related contact

Issue

	- Create a second company
	- Create user with access to main and second company
	- Go to "Contacts" app
	- Edit contact of the new user, and under the "Sales & Purchases" tab,
	  ensure that the company field is set
	- Create a new contact with same email of the new user
	- In list view, select both contact related to new user
	- Click on Action->Merge Selected Contacts, then merge contacts

	User has no more access to both companies, only company related to
	merged destination Contact/Partner.

Cause

	All related companies are unliked from user, and instead overwrited
	with one company related of the merged destination Contact/Partner.

Solution

	Instead of unlink all companies, we will only add the contact company
	to the allowed companies of the user.

opw-2269397

closes odoo/odoo#52620

X-original-commit: e00b23b73f00fb24b2771ea8894031b35204e65e
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
Nasreddin (bon)
2020-06-08 15:04:06 +00:00
parent 315346ad28
commit c503faab53
@@ -311,9 +311,10 @@ class MergePartnerAutomatic(models.TransientModel):
# Make the company of all related users consistent with destination partner company
if dst_partner.company_id:
for user in partner_ids.mapped('user_ids'):
user.sudo().write({'company_ids': [(6, 0, [dst_partner.company_id.id])],
'company_id': dst_partner.company_id.id})
partner_ids.mapped('user_ids').sudo().write({
'company_ids': [(4, dst_partner.company_id.id)],
'company_id': dst_partner.company_id.id
})
# call sub methods to do the merge
self._update_foreign_keys(src_partners, dst_partner)