From bc049012f7fd97256618931e44197671e0dff558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=C3=B4i=20=28Ki=C3=AAn=20Kim=29?= Date: Tue, 8 Oct 2024 15:14:05 +0700 Subject: [PATCH] [MIG] mail_restrict_follower_selection: Migration to 18.0 --- mail_restrict_follower_selection/README.rst | 16 +++++------ .../__manifest__.py | 4 +-- .../models/mail_followers.py | 8 ++++-- .../models/mail_thread.py | 26 ++++++++--------- .../models/mail_wizard_invite.py | 2 +- .../static/description/index.html | 8 +++--- .../test_mail_restrict_follower_selection.py | 28 +++++++++---------- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/mail_restrict_follower_selection/README.rst b/mail_restrict_follower_selection/README.rst index 25cdb400..27fb8e90 100644 --- a/mail_restrict_follower_selection/README.rst +++ b/mail_restrict_follower_selection/README.rst @@ -16,14 +16,14 @@ Restrict follower selection .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github - :target: https://github.com/OCA/social/tree/18.0/mail_restrict_follower_selection - :alt: OCA/social +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_restrict_follower_selection + :alt: OCA/mail .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_restrict_follower_selection + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_restrict_follower_selection :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=18.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -61,10 +61,10 @@ Note: This module won't change existing followers! Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -100,6 +100,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/social `_ project on GitHub. +This module is part of the `OCA/mail `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_restrict_follower_selection/__manifest__.py b/mail_restrict_follower_selection/__manifest__.py index 84eb63be..63272220 100644 --- a/mail_restrict_follower_selection/__manifest__.py +++ b/mail_restrict_follower_selection/__manifest__.py @@ -4,11 +4,11 @@ { "name": "Restrict follower selection", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "author": "Therp BV,Creu Blanca,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Social Network", - "website": "https://github.com/OCA/social", + "website": "https://github.com/OCA/mail", "summary": "Define a domain from which followers can be selected", "depends": ["mail"], "data": ["data/ir_config_parameter.xml", "data/ir_actions.xml"], diff --git a/mail_restrict_follower_selection/models/mail_followers.py b/mail_restrict_follower_selection/models/mail_followers.py index fc4235e3..9b942bb6 100644 --- a/mail_restrict_follower_selection/models/mail_followers.py +++ b/mail_restrict_follower_selection/models/mail_followers.py @@ -32,9 +32,11 @@ def _add_followers( check_existing=check_existing, existing_policy=existing_policy, ) - domain = self.env[ - "mail.wizard.invite" - ]._mail_restrict_follower_selection_get_domain(res_model=res_model) + domain = str( + self.env["mail.wizard.invite"]._mail_restrict_follower_selection_get_domain( + res_model=res_model + ) + ) partners = self.env["res.partner"].search( [("id", "in", partner_ids)] + safe_eval( diff --git a/mail_restrict_follower_selection/models/mail_thread.py b/mail_restrict_follower_selection/models/mail_thread.py index 740bb91a..56af2452 100644 --- a/mail_restrict_follower_selection/models/mail_thread.py +++ b/mail_restrict_follower_selection/models/mail_thread.py @@ -23,18 +23,18 @@ def _message_add_suggested_recipient( "mail.wizard.invite" ]._mail_restrict_follower_selection_get_domain() eval_domain = safe_eval( - domain, locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)} + str(domain), locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)} ) - for key in result: - items_to_remove = [] - for item in result[key]: - partner_id = item[0] - if partner_id: - partner = self.env["res.partner"].search( - [("id", "=", partner_id)] + eval_domain - ) - if not partner: - items_to_remove.append(item) - for item in items_to_remove: - result[key].remove(item) + items_to_remove = [] + for item in result: + partner_id = item.get("partner_id", False) + if partner_id: + partner_count = self.env["res.partner"].search_count( + [("id", "=", partner_id)] + eval_domain + ) + if not partner_count: + items_to_remove.append(item) + for item in items_to_remove: + result.remove(item) + return result diff --git a/mail_restrict_follower_selection/models/mail_wizard_invite.py b/mail_restrict_follower_selection/models/mail_wizard_invite.py index f60257df..24cadd3e 100644 --- a/mail_restrict_follower_selection/models/mail_wizard_invite.py +++ b/mail_restrict_follower_selection/models/mail_wizard_invite.py @@ -41,7 +41,7 @@ def get_view(self, view_id=None, view_type="form", **options): arch = etree.fromstring(result["arch"]) domain = self._mail_restrict_follower_selection_get_domain() eval_domain = safe_eval( - domain, locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)} + str(domain), locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)} ) for field in arch.xpath('//field[@name="partner_ids"]'): field.attrib["domain"] = str(eval_domain) diff --git a/mail_restrict_follower_selection/static/description/index.html b/mail_restrict_follower_selection/static/description/index.html index ebfa18c3..183d454e 100644 --- a/mail_restrict_follower_selection/static/description/index.html +++ b/mail_restrict_follower_selection/static/description/index.html @@ -369,7 +369,7 @@

Restrict follower selection

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:5afe605fd4213b36044bc3ff7b459c564bbb92a3bbad79765ad83bd596d687ff !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/mail Translate me on Weblate Try me on Runboat

This module was written to allow you to restrict the selection of possible followers. For example, if you use the social ERP functions only internally, it makes sense to filter possible followers for being @@ -405,10 +405,10 @@

Configuration

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -441,7 +441,7 @@

Maintainers

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/social project on GitHub.

+

This module is part of the OCA/mail project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py index a8ccb3ad..e01f50e9 100644 --- a/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py +++ b/mail_restrict_follower_selection/tests/test_mail_restrict_follower_selection.py @@ -30,7 +30,8 @@ def setUp(self): def _use_ref_in_domain(self): """Change the general domain to test the safe_eval.""" param = self.env.ref("mail_restrict_follower_selection.parameter_domain") - param.value = "[('country_id', '!=', ref('base.ch'))]" + country_id = self.env.ref("base.ch").id + param.value = f"[('country_id', '!=', {country_id})]" def test_fields_view_get(self): result = self.env["mail.wizard.invite"].get_view(view_type="form") @@ -78,18 +79,18 @@ def test_followers_not_meet(self): def test_message_add_suggested_recipient(self): res = self.partner.with_context( test_restrict_follower=True - )._message_add_suggested_recipient({self.partner.id: []}, partner=self.partner) - self.assertEqual(res[self.partner.id][0][0], self.partner.id) + )._message_add_suggested_recipient([], partner=self.partner) + self.assertEqual(res[0]["partner_id"], self.partner.id) new_res = self.partner.with_context( test_restrict_follower=True - )._message_add_suggested_recipient({self.partner.id: []}) - self.assertFalse(new_res[self.partner.id][0][0]) + )._message_add_suggested_recipient([]) + self.assertFalse(new_res[0].get("partner_id")) - def test_fields_view_get_eval(self): + def test_get_view_eval(self): """Check using safe_eval in field_view_get.""" self._use_ref_in_domain() - result = self.env["mail.wizard.invite"].fields_view_get(view_type="form") + result = self.env["mail.wizard.invite"].get_view(view_type="form") for field in etree.fromstring(result["arch"]).xpath( '//field[@name="partner_ids"]' ): @@ -101,13 +102,10 @@ def test_message_add_suggested_recipient_eval(self): """Check using safe_eval when adding recipients.""" self._use_ref_in_domain() partner = self.partner.with_context(test_restrict_follower=True) - res = partner._message_add_suggested_recipient( - {self.partner.id: []}, partner=self.partner - ) - self.assertEqual(res[self.partner.id][0][0], self.partner.id) + res = partner._message_add_suggested_recipient([], partner=self.partner) + self.assertEqual(res[0]["partner_id"], self.partner.id) + # Partner from Swizterland should be excluded partner.country_id = self.switzerland - res = partner._message_add_suggested_recipient( - {self.partner.id: []}, partner=self.partner - ) - self.assertFalse(res[self.partner.id]) + res = partner._message_add_suggested_recipient([], partner=self.partner) + self.assertFalse(res)