From 51856cca4a7bb36cd25b34798f5914df787c0f4e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 22 Mar 2019 16:07:41 +0100 Subject: [PATCH] [MIG] partner_deduplicate_acl: Complete migration Now there's an argument for controlling extra checks --- partner_deduplicate_acl/__init__.py | 2 -- partner_deduplicate_acl/models/__init__.py | 3 --- partner_deduplicate_acl/models/res_partner.py | 16 ------------ ...acl.py => test_partner_deduplicate_acl.py} | 11 +++----- .../wizards/partner_merge.py | 25 ++++++++----------- 5 files changed, 13 insertions(+), 44 deletions(-) delete mode 100644 partner_deduplicate_acl/models/__init__.py delete mode 100644 partner_deduplicate_acl/models/res_partner.py rename partner_deduplicate_acl/tests/{test_crm_deduplicate_acl.py => test_partner_deduplicate_acl.py} (80%) diff --git a/partner_deduplicate_acl/__init__.py b/partner_deduplicate_acl/__init__.py index ef2bd060e..2d2a05ce9 100644 --- a/partner_deduplicate_acl/__init__.py +++ b/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). -from . import models from . import wizards diff --git a/partner_deduplicate_acl/models/__init__.py b/partner_deduplicate_acl/models/__init__.py deleted file mode 100644 index ccebc7247..000000000 --- a/partner_deduplicate_acl/models/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from . import res_partner diff --git a/partner_deduplicate_acl/models/res_partner.py b/partner_deduplicate_acl/models/res_partner.py deleted file mode 100644 index 2d9f246f9..000000000 --- a/partner_deduplicate_acl/models/res_partner.py +++ /dev/null @@ -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) diff --git a/partner_deduplicate_acl/tests/test_crm_deduplicate_acl.py b/partner_deduplicate_acl/tests/test_partner_deduplicate_acl.py similarity index 80% rename from partner_deduplicate_acl/tests/test_crm_deduplicate_acl.py rename to partner_deduplicate_acl/tests/test_partner_deduplicate_acl.py index d7bf3944f..5300c9633 100644 --- a/partner_deduplicate_acl/tests/test_crm_deduplicate_acl.py +++ b/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). from odoo import exceptions from odoo.tests import common -class TestCrmDeduplicateAcl(common.TransactionCase): +class TestPartnerDeduplicateAcl(common.TransactionCase): def setUp(self): - super(TestCrmDeduplicateAcl, self).setUp() + super(TestPartnerDeduplicateAcl, self).setUp() self.partner_1 = self.env['res.partner'].create({ 'name': 'Partner 1', 'email': 'partner1@example.org', @@ -42,9 +43,3 @@ class TestCrmDeduplicateAcl(common.TransactionCase): ] # Now there shouldn't be error 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, - ) diff --git a/partner_deduplicate_acl/wizards/partner_merge.py b/partner_deduplicate_acl/wizards/partner_merge.py index 8c932c566..38a5e71d7 100644 --- a/partner_deduplicate_acl/wizards/partner_merge.py +++ b/partner_deduplicate_acl/wizards/partner_merge.py @@ -1,6 +1,6 @@ # Copyright 2016 Tecnativa - Jairo Llopis # 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). from odoo import models @@ -9,19 +9,14 @@ from odoo import models class BasePartnerMergeAutomaticWizard(models.TransientModel): _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, )