From c503faab534bf23ec194424ac584d697f6b22874 Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Thu, 4 Jun 2020 15:25:20 +0000 Subject: [PATCH] [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) Signed-off-by: bon-odoo --- odoo/addons/base/wizard/base_partner_merge.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/wizard/base_partner_merge.py b/odoo/addons/base/wizard/base_partner_merge.py index 394144a72be..fe9dd800bb3 100644 --- a/odoo/addons/base/wizard/base_partner_merge.py +++ b/odoo/addons/base/wizard/base_partner_merge.py @@ -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)