From 105005d6465068c185c5919f581150edd618fce9 Mon Sep 17 00:00:00 2001
From: chien
Date: Tue, 23 Jan 2024 18:08:10 +0700
Subject: [PATCH] [MIG] base_search_mail_content: Migration to 17.0
---
base_search_mail_content/README.rst | 11 ++---
base_search_mail_content/__manifest__.py | 5 +--
.../data/trgm_index_data.xml | 44 -------------------
base_search_mail_content/models/__init__.py | 2 +-
.../models/mail_message.py | 17 +++++++
base_search_mail_content/models/trgm_index.py | 17 -------
.../readme/CONTRIBUTORS.md | 1 +
base_search_mail_content/readme/INSTALL.md | 8 +---
.../static/description/index.html | 10 ++---
.../tests/test_base_search_mail_content.py | 4 +-
10 files changed, 31 insertions(+), 88 deletions(-)
delete mode 100644 base_search_mail_content/data/trgm_index_data.xml
create mode 100644 base_search_mail_content/models/mail_message.py
delete mode 100644 base_search_mail_content/models/trgm_index.py
diff --git a/base_search_mail_content/README.rst b/base_search_mail_content/README.rst
index 88bdf384a..3e53d0d76 100644
--- a/base_search_mail_content/README.rst
+++ b/base_search_mail_content/README.rst
@@ -58,13 +58,8 @@ body, email from, reply to and record name.
Installation
============
-This module depends on the module 'base_search_fuzzy' to ensure that
-searches on emails are based on indexes. Please read carefully the
-`install
-instructions `__.
-
-This module installs by default the indexes that are required to perform
-the searches on mail messages.
+This module creates the GIN (trigram) indexes for these fields of
+mail.message: subject, body, record_name, email_from, reply_to.
Usage
=====
@@ -104,6 +99,8 @@ Contributors
- Vicent Cubells
- Ernesto Tejeda
+- Nguyen Minh Chien
+
Maintainers
-----------
diff --git a/base_search_mail_content/__manifest__.py b/base_search_mail_content/__manifest__.py
index 95a125486..6861d9d02 100644
--- a/base_search_mail_content/__manifest__.py
+++ b/base_search_mail_content/__manifest__.py
@@ -6,12 +6,11 @@
{
"name": "Base Search Mail Content",
- "version": "16.0.1.0.2",
+ "version": "17.0.1.0.0",
"author": "ForgeFlow, SerpentCS, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"category": "Social",
- "data": ["data/trgm_index_data.xml"],
- "depends": ["mail", "base_search_fuzzy"],
+ "depends": ["mail"],
"license": "AGPL-3",
"installable": True,
}
diff --git a/base_search_mail_content/data/trgm_index_data.xml b/base_search_mail_content/data/trgm_index_data.xml
deleted file mode 100644
index b75f071d3..000000000
--- a/base_search_mail_content/data/trgm_index_data.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
- gin
-
-
-
-
- gin
-
-
-
-
- gin
-
-
-
-
- gin
-
-
-
-
- gin
-
-
-
-
diff --git a/base_search_mail_content/models/__init__.py b/base_search_mail_content/models/__init__.py
index c3127c500..1684e4f2f 100644
--- a/base_search_mail_content/models/__init__.py
+++ b/base_search_mail_content/models/__init__.py
@@ -4,5 +4,5 @@
# ()
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
+from . import mail_message
from . import mail_thread
-from . import trgm_index
diff --git a/base_search_mail_content/models/mail_message.py b/base_search_mail_content/models/mail_message.py
new file mode 100644
index 000000000..44644910b
--- /dev/null
+++ b/base_search_mail_content/models/mail_message.py
@@ -0,0 +1,17 @@
+# Copyright 2016 ForgeFlow S.L.
+# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
+# Copyright 2017 LasLabs Inc.
+# Copyright 2018 Tecnativa - Vicent Cubells
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import fields, models
+
+
+class MailMessage(models.Model):
+ _inherit = "mail.message"
+
+ subject = fields.Char(index="trigram")
+ body = fields.Html(index="trigram")
+ record_name = fields.Char(index="trigram")
+ email_from = fields.Char(index="trigram")
+ reply_to = fields.Char(index="trigram")
diff --git a/base_search_mail_content/models/trgm_index.py b/base_search_mail_content/models/trgm_index.py
deleted file mode 100644
index 60267648e..000000000
--- a/base_search_mail_content/models/trgm_index.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2016 ForgeFlow S.L.
-# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
-# Copyright 2017 LasLabs Inc.
-# Copyright 2018 Tecnativa - Vicent Cubells
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
-from odoo import fields, models
-
-
-class TrgmIndex(models.Model):
- _inherit = "trgm.index"
-
- # We take advantage of field inheritance to redefine help instead of do
- # inheritance in views that throws an error
- field_id = fields.Many2one(
- help="You can either select a field of type 'text', 'char' or 'html'."
- )
diff --git a/base_search_mail_content/readme/CONTRIBUTORS.md b/base_search_mail_content/readme/CONTRIBUTORS.md
index 0e56e699b..540ac21d6 100644
--- a/base_search_mail_content/readme/CONTRIBUTORS.md
+++ b/base_search_mail_content/readme/CONTRIBUTORS.md
@@ -5,3 +5,4 @@
- [Tecnativa](https://www.tecnativa.com):
- Vicent Cubells
- Ernesto Tejeda
+- Nguyen Minh Chien \<\>
diff --git a/base_search_mail_content/readme/INSTALL.md b/base_search_mail_content/readme/INSTALL.md
index 41256c41c..00663baad 100644
--- a/base_search_mail_content/readme/INSTALL.md
+++ b/base_search_mail_content/readme/INSTALL.md
@@ -1,7 +1 @@
-This module depends on the module 'base_search_fuzzy' to ensure that
-searches on emails are based on indexes. Please read carefully the
-[install
-instructions](https://github.com/OCA/server-tools/blob/15.0/base_search_fuzzy).
-
-This module installs by default the indexes that are required to perform
-the searches on mail messages.
+This module creates the GIN (trigram) indexes for these fields of mail.message: subject, body, record_name, email_from, reply_to.
diff --git a/base_search_mail_content/static/description/index.html b/base_search_mail_content/static/description/index.html
index ca2a8e8ad..c2a85bd92 100644
--- a/base_search_mail_content/static/description/index.html
+++ b/base_search_mail_content/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -402,12 +401,8 @@ body, email from, reply to and record name.
-
This module depends on the module ‘base_search_fuzzy’ to ensure that
-searches on emails are based on indexes. Please read carefully the
-install
-instructions.
-
This module installs by default the indexes that are required to perform
-the searches on mail messages.
+
This module creates the GIN (trigram) indexes for these fields of
+mail.message: subject, body, record_name, email_from, reply_to.
@@ -444,6 +439,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
Ernesto Tejeda
+
Nguyen Minh Chien <chien@trobz.com>
diff --git a/base_search_mail_content/tests/test_base_search_mail_content.py b/base_search_mail_content/tests/test_base_search_mail_content.py
index b745fed98..cb8d66e70 100644
--- a/base_search_mail_content/tests/test_base_search_mail_content.py
+++ b/base_search_mail_content/tests/test_base_search_mail_content.py
@@ -7,7 +7,7 @@ from odoo.tests.common import TransactionCase
class TestBaseSearchMailContent(TransactionCase):
def setUp(self):
super().setUp()
- self.channel_obj = self.env["mail.channel"]
+ self.channel_obj = self.env["discuss.channel"]
def test_base_search_mail_content_1(self):
res = self.channel_obj.search([("message_content", "ilike", "xxxyyyzzz")])
@@ -20,6 +20,6 @@ class TestBaseSearchMailContent(TransactionCase):
)
self.assertIn(
"message_content",
- res["models"]["mail.channel"],
+ res["models"][self.channel_obj._name],
"message_content field was not detected",
)