Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] base: Partners with followers in common can be merged #12

Open
wants to merge 1 commit into
base: 14.0-dont-delete-merged-partners-fer
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions odoo/addons/base/wizard/base_partner_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ def _update_foreign_keys(self, src_partners, dst_partner):
except psycopg2.Error as e:
# updating fails, most likely due to a violated unique constraint
# keeping record with nonexistent partner_id is useless, better delete it
msg="""An error has ocurred meanwhile foreign keys were updated \n Destination Record: %s \nSource Record: %s, \nError: %s""" % (dst_partner.id, tuple(src_partners.ids), e)
_logger.error(msg)
raise UserError(msg)
if e.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:
query = 'DELETE FROM "%(table)s" WHERE "%(column)s" IN %%s' % query_dic
self._cr.execute(query, (tuple(src_partners.ids),))
else:
msg="""An error has ocurred meanwhile foreign keys were updated \n Destination Record: %s \nSource Record: %s, \nError: %s""" % (dst_partner.id, tuple(src_partners.ids), e)
_logger.error(msg)
raise UserError(msg)

self.invalidate_cache()

Expand All @@ -199,7 +203,7 @@ def update_records(model, src, field_model='model', field_id='res_id'):
# updating fails, most likely due to a violated unique constraint
# keeping record with nonexistent partner_id is useless, better delete it
# An example of this is with partners that have followers in common:
if model == "mail.followers" and e.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:
if e.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:
records.sudo().unlink()
else:
# Everything else is not expected and should fail.
Expand Down