File: base_partner_merge.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (31 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Part of Odoo. See LICENSE file for full copyright and licensing details.


from odoo import api, models


class MergePartnerAutomatic(models.TransientModel):
    _inherit = 'base.partner.merge.automatic.wizard'

    @api.model
    def _update_foreign_keys(self, src_partners, dst_partner):
        # Case 1: there is a visitor for both src and dst partners.
        # Need to merge visitors before `super` to avoid SQL partner_id unique
        # constraint to raise as it will change partner_id of the visitor
        # record(s) to the `dst_partner` which already exists.
        dst_visitor = dst_partner.visitor_ids and dst_partner.visitor_ids[0]
        if dst_visitor:
            for visitor in src_partners.visitor_ids:
                visitor._merge_visitor(dst_visitor)

        super()._update_foreign_keys(src_partners, dst_partner)

        # Case 2: there is a visitor only for src_partners.
        # Need to fix the "de-sync" values between `access_token` and
        # `partner_id`.
        self.env.cr.execute("""
            UPDATE website_visitor
               SET access_token = partner_id
             WHERE partner_id::int != access_token::int
               AND partner_id = %s;
        """, (dst_partner.id,))