From 20ccfebbadd37eaa182375dd9c1625d2aa300f3b Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 9 Oct 2023 17:19:48 +0200 Subject: [PATCH 1/6] [FIX] connector_search_engine: Fix binding form view --- connector_search_engine/views/se_binding_view.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/connector_search_engine/views/se_binding_view.xml b/connector_search_engine/views/se_binding_view.xml index 777bfe95..31915fa1 100644 --- a/connector_search_engine/views/se_binding_view.xml +++ b/connector_search_engine/views/se_binding_view.xml @@ -33,10 +33,17 @@ - + - + + From 6a41d81dd26068999fe7d4c45962c7233fe9f544 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 9 Oct 2023 17:20:51 +0200 Subject: [PATCH 2/6] [FIX] connector_search_engine: Makes admin a Search Engine Connector Manager --- .../security/connector_search_engine_security.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connector_search_engine/security/connector_search_engine_security.xml b/connector_search_engine/security/connector_search_engine_security.xml index 75db9aec..df9cee64 100644 --- a/connector_search_engine/security/connector_search_engine_security.xml +++ b/connector_search_engine/security/connector_search_engine_security.xml @@ -7,7 +7,10 @@ Search Engine Connector Manager - + Date: Mon, 9 Oct 2023 17:22:09 +0200 Subject: [PATCH 3/6] [IMP] connector_search_engine: Add wizard to update binding's state --- connector_search_engine/__init__.py | 1 + connector_search_engine/__manifest__.py | 1 + .../readme/newsfragments/.gitignore | 0 .../security/ir.model.access.csv | 1 + connector_search_engine/wizards/__init__.py | 1 + .../wizards/se_binding_state_updater.py | 19 +++++++++++ .../wizards/se_binding_state_updater.xml | 33 +++++++++++++++++++ 7 files changed, 56 insertions(+) create mode 100644 connector_search_engine/readme/newsfragments/.gitignore create mode 100644 connector_search_engine/wizards/__init__.py create mode 100644 connector_search_engine/wizards/se_binding_state_updater.py create mode 100644 connector_search_engine/wizards/se_binding_state_updater.xml diff --git a/connector_search_engine/__init__.py b/connector_search_engine/__init__.py index fbdd7c8a..863c881e 100644 --- a/connector_search_engine/__init__.py +++ b/connector_search_engine/__init__.py @@ -4,3 +4,4 @@ from . import models # pragma: no cover from . import tools +from . import wizards diff --git a/connector_search_engine/__manifest__.py b/connector_search_engine/__manifest__.py index e4374822..212245be 100644 --- a/connector_search_engine/__manifest__.py +++ b/connector_search_engine/__manifest__.py @@ -15,6 +15,7 @@ "depends": ["queue_job", "mail", "server_environment"], "external_dependencies": {"python": ["unidecode"]}, "data": [ + "wizards/se_binding_state_updater.xml", "security/connector_search_engine_security.xml", "security/se_index_config.xml", "security/ir.model.access.csv", diff --git a/connector_search_engine/readme/newsfragments/.gitignore b/connector_search_engine/readme/newsfragments/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/connector_search_engine/security/ir.model.access.csv b/connector_search_engine/security/ir.model.access.csv index 51e5f7f5..5dd95102 100644 --- a/connector_search_engine/security/ir.model.access.csv +++ b/connector_search_engine/security/ir.model.access.csv @@ -5,3 +5,4 @@ access_manager_se_binding,Search Engine Binding connector manager,model_se_bindi access_user_se_backend,Search Engine Backend connector user,model_se_backend,group_connector_search_engine_user,1,0,0,0 access_user_se_index,Search Engine Index connector user,model_se_index,group_connector_search_engine_user,1,0,0,0 access_user_se_binding,Search Engine Binding connector user,model_se_binding,group_connector_search_engine_user,1,0,0,0 +access_manager_se_binding_state_updater,Search Engine Binding State Updater,model_se_binding_state_updater,group_connector_search_engine_manager,1,1,1,1 diff --git a/connector_search_engine/wizards/__init__.py b/connector_search_engine/wizards/__init__.py new file mode 100644 index 00000000..285f78d1 --- /dev/null +++ b/connector_search_engine/wizards/__init__.py @@ -0,0 +1 @@ +from . import se_binding_state_updater diff --git a/connector_search_engine/wizards/se_binding_state_updater.py b/connector_search_engine/wizards/se_binding_state_updater.py new file mode 100644 index 00000000..687ea084 --- /dev/null +++ b/connector_search_engine/wizards/se_binding_state_updater.py @@ -0,0 +1,19 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SeBindingStateUpdater(models.TransientModel): + + _name = "se.binding.state.updater" + + state = fields.Selection( + string="New state", + selection=lambda self: self.env["se.binding"]._fields["state"].selection, + required=True, + ) + + def doit(self): + res_ids = self.env.context.get("active_ids") + self.env["se.binding"].browse(res_ids).write({"state": self.state}) diff --git a/connector_search_engine/wizards/se_binding_state_updater.xml b/connector_search_engine/wizards/se_binding_state_updater.xml new file mode 100644 index 00000000..5e11eee1 --- /dev/null +++ b/connector_search_engine/wizards/se_binding_state_updater.xml @@ -0,0 +1,33 @@ + + + + + + se.binding.state.updater.form (in connector_search_engine) + se.binding.state.updater + +
+ + + +
+
+
+
+
+ + + Update state + se.binding.state.updater + form + + new + + + +
From e6f189e7c5a49db1e84824590f3a72ce7e545eb7 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 9 Oct 2023 18:23:54 +0200 Subject: [PATCH 4/6] [IMP] connector_search_engine: Add quick access to bindings Add a smart button to quickly access to the bound records from the *Search Engine Backend* and *Search Engine Record* views. --- connector_search_engine/models/se_backend.py | 20 ++++++++++++++++++ connector_search_engine/models/se_index.py | 13 +++++++++++- connector_search_engine/views/se_backend.xml | 22 ++++++++++++++++++++ connector_search_engine/views/se_index.xml | 22 ++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/connector_search_engine/models/se_backend.py b/connector_search_engine/models/se_backend.py index 1585a4bc..7e50b5b9 100644 --- a/connector_search_engine/models/se_backend.py +++ b/connector_search_engine/models/se_backend.py @@ -26,6 +26,20 @@ class SeBackend(models.Model): backend_type = fields.Selection(selection=[], string="Type", required=True) index_ids = fields.One2many("se.index", "backend_id") + binding_ids = fields.One2many("se.binding", "backend_id") + + binding_count = fields.Integer(compute="_compute_binding_count") + + @api.depends("binding_ids") + def _compute_binding_count(self): + res = self.env["se.binding"].read_group( + [("backend_id", "in", self.ids)], + ["backend_id"], + ["backend_id"], + ) + mapped_data = {r["backend_id"][0]: r["backend_id_count"] for r in res} + for record in self: + record.binding_count = mapped_data.get(record.id, 0) @property def _server_env_fields(self): @@ -71,3 +85,9 @@ def action_test_connection(self): "sticky": False, }, } + + def action_open_bindings(self): + self.ensure_one() + action = self.env.ref("connector_search_engine.se_binding_action").read()[0] + action["domain"] = [("backend_id", "=", self.id)] + return action diff --git a/connector_search_engine/models/se_index.py b/connector_search_engine/models/se_index.py index 77d3d4ea..a81332ea 100644 --- a/connector_search_engine/models/se_index.py +++ b/connector_search_engine/models/se_index.py @@ -57,6 +57,7 @@ class SeIndex(models.Model): count_done = fields.Integer(compute="_compute_count_binding") count_pending = fields.Integer(compute="_compute_count_binding") count_error = fields.Integer(compute="_compute_count_binding") + count_all = fields.Integer(compute="_compute_count_binding") @api.depends("binding_ids.state") def _compute_count_binding(self): @@ -69,8 +70,11 @@ def _compute_count_binding(self): groupby=["index_id", "state"], lazy=False, ) + all = 0 for item in data: - res[item["index_id"][0]][item["state"]] = item["__count"] + count = item["__count"] + res[item["index_id"][0]][item["state"]] = count + all += count def get(index_id, states): return sum([res[index_id][state] for state in states]) @@ -89,6 +93,7 @@ def get(index_id, states): ], ) record.count_error = get(record.id, ["invalid_data", "recompute_error"]) + record.count_all = all if record.count_error: record.color = 1 elif record.count_pending: @@ -376,3 +381,9 @@ def resynchronize_all_bindings(self): def delete_obsolete_item(self, item_ids: List[int]): self.se_adapter.delete(item_ids) return f"Deleted ids : {item_ids}" + + def action_open_bindings(self): + self.ensure_one() + action = self.env.ref("connector_search_engine.se_binding_action").read()[0] + action["domain"] = [("index_id", "=", self.id)] + return action diff --git a/connector_search_engine/views/se_backend.xml b/connector_search_engine/views/se_backend.xml index 47d97d06..373de2b8 100644 --- a/connector_search_engine/views/se_backend.xml +++ b/connector_search_engine/views/se_backend.xml @@ -15,6 +15,28 @@ /> +
+ +