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/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/models/se_indexable_record.py b/connector_search_engine/models/se_indexable_record.py index 0447e1aa..ecdeb907 100644 --- a/connector_search_engine/models/se_indexable_record.py +++ b/connector_search_engine/models/se_indexable_record.py @@ -121,13 +121,10 @@ def _compute_count_binding(self): ) def _get_bindings(self, indexes: SeIndex = None) -> SeBinding: - domain = [ - ("res_model", "=", self._name), - ("res_id", "in", self.ids), - ] + bindings = self.se_binding_ids if indexes: - domain.append(("index_id", "in", indexes.ids)) - return self.env["se.binding"].search(domain) + bindings = bindings.filtered(lambda s: s.index_id in indexes) + return bindings def _add_to_index(self, indexes: SeIndex) -> SeBinding: """Add the record to the index. 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/readme/newsfragments/162.bugfix b/connector_search_engine/readme/newsfragments/162.bugfix new file mode 100644 index 00000000..e209cc15 --- /dev/null +++ b/connector_search_engine/readme/newsfragments/162.bugfix @@ -0,0 +1,4 @@ +Fix Search Engine Binding form view. The fields data and error are now +properly displayed and fit the width of the form. + +Makes the Odoo's admin user a member of the *Search Engine Connector Manager* group. diff --git a/connector_search_engine/readme/newsfragments/162.feature b/connector_search_engine/readme/newsfragments/162.feature new file mode 100644 index 00000000..9981d5ad --- /dev/null +++ b/connector_search_engine/readme/newsfragments/162.feature @@ -0,0 +1,5 @@ +A new action **Update state** is now available on *Search Engine Record* objects. +This action allows you to update the state of selected records on the tree view. + +Add a smart button to quickly access to the bound records from the +*Search Engine Backend* and *Search Engine Record* views. 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 - + +
+ +