Browse Source

[MIG] partner_deduplicate_acl: Complete migration

Now there's an argument for controlling extra checks
14.0
Pedro M. Baeza 6 years ago
committed by Carlos Roca
parent
commit
51856cca4a
  1. 2
      partner_deduplicate_acl/__init__.py
  2. 3
      partner_deduplicate_acl/models/__init__.py
  3. 16
      partner_deduplicate_acl/models/res_partner.py
  4. 11
      partner_deduplicate_acl/tests/test_partner_deduplicate_acl.py
  5. 25
      partner_deduplicate_acl/wizards/partner_merge.py

2
partner_deduplicate_acl/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizards from . import wizards

3
partner_deduplicate_acl/models/__init__.py

@ -1,3 +0,0 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import res_partner

16
partner_deduplicate_acl/models/res_partner.py

@ -1,16 +0,0 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.returns('self', lambda value: value.id)
def message_post(self, *args, **kwargs):
"""Change user who is posting the message if set by context."""
if self.env.context.get('message_post_user'):
obj = self.sudo(self.env.context['message_post_user'])
else:
obj = self
return super(ResPartner, obj).message_post(*args, **kwargs)

11
partner_deduplicate_acl/tests/test_crm_deduplicate_acl.py → partner_deduplicate_acl/tests/test_partner_deduplicate_acl.py

@ -1,12 +1,13 @@
# Copyright 2017-2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import exceptions from odoo import exceptions
from odoo.tests import common from odoo.tests import common
class TestCrmDeduplicateAcl(common.TransactionCase):
class TestPartnerDeduplicateAcl(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestCrmDeduplicateAcl, self).setUp()
super(TestPartnerDeduplicateAcl, self).setUp()
self.partner_1 = self.env['res.partner'].create({ self.partner_1 = self.env['res.partner'].create({
'name': 'Partner 1', 'name': 'Partner 1',
'email': 'partner1@example.org', 'email': 'partner1@example.org',
@ -42,9 +43,3 @@ class TestCrmDeduplicateAcl(common.TransactionCase):
] ]
# Now there shouldn't be error # Now there shouldn't be error
self.wizard.action_merge() self.wizard.action_merge()
# Check that the posted message has correct user
resulting_partner = (self.partner_1 + self.partner_2).exists()
self.assertEqual(
resulting_partner.message_ids[0].author_id,
self.user.partner_id,
)

25
partner_deduplicate_acl/wizards/partner_merge.py

@ -1,6 +1,6 @@
# Copyright 2016 Tecnativa - Jairo Llopis # Copyright 2016 Tecnativa - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# Copyright 2017 Tecnativa - Pedro M. Baeza
# Copyright 2017-2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models from odoo import models
@ -9,19 +9,14 @@ from odoo import models
class BasePartnerMergeAutomaticWizard(models.TransientModel): class BasePartnerMergeAutomaticWizard(models.TransientModel):
_inherit = "base.partner.merge.automatic.wizard" _inherit = "base.partner.merge.automatic.wizard"
def _merge(self, partner_ids, dst_partner=None):
"""Perform the operation as admin if you have unrestricted merge
rights to avoid the rise of exceptions. An special context key is
passed for preserving the message author.
def _merge(self, partner_ids, dst_partner=None, extra_checks=True):
"""Pass extra_checks=False if we have the extra group for avoiding
the checks.
""" """
if self.env.user.has_group('partner_deduplicate_acl.group_unrestricted'):
obj = self.sudo().with_context(message_post_user=self.env.uid)
if dst_partner:
dst_partner = dst_partner.with_context(
message_post_user=self.env.uid,
)
else:
obj = self
return super(BasePartnerMergeAutomaticWizard, obj)._merge(
partner_ids, dst_partner=dst_partner,
if self.env.user.has_group(
'partner_deduplicate_acl.group_unrestricted'
):
extra_checks = False
return super()._merge(
partner_ids, dst_partner=dst_partner, extra_checks=extra_checks,
) )
Loading…
Cancel
Save