Skip to content

Commit

Permalink
Merge PR #162 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Oct 13, 2023
2 parents 315da25 + b5676fc commit 2399680
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 10 deletions.
1 change: 1 addition & 0 deletions connector_search_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

from . import models # pragma: no cover
from . import tools
from . import wizards
1 change: 1 addition & 0 deletions connector_search_engine/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions connector_search_engine/models/se_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion connector_search_engine/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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])
Expand All @@ -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:
Expand Down Expand Up @@ -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
9 changes: 3 additions & 6 deletions connector_search_engine/models/se_indexable_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions connector_search_engine/readme/newsfragments/162.bugfix
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions connector_search_engine/readme/newsfragments/162.feature
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

<record id="group_connector_search_engine_manager" model="res.groups">
<field name="name">Search Engine Connector Manager</field>
<field name="users" eval="[Command.link(ref('base.user_root'))]" />
<field
name="users"
eval="[Command.link(ref('base.user_root')), Command.link(ref('base.user_admin'))]"
/>
<field
name="implied_ids"
eval="[Command.link(ref('group_connector_search_engine_user'))]"
Expand Down
1 change: 1 addition & 0 deletions connector_search_engine/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions connector_search_engine/views/se_backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@
/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button
name="action_open_bindings"
type="object"
class="oe_stat_button"
icon="fa-list-ul"
context="{'search_default_groupby_model': 1}"
>

<div class="o_stat_info">
<field name="binding_count" class="o_stat_value" />
<span
class="o_stat_text"
attrs="{'invisible': [('binding_count', '&lt;', 2)]}"
> Bindings</span>
<span
class="o_stat_text"
attrs="{'invisible': [('binding_count', '&gt;', 1)]}"
> Binding</span>
</div>
</button>
</div>
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" class="oe_inline" required="1" />
Expand Down
11 changes: 9 additions & 2 deletions connector_search_engine/views/se_binding_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@
<field name="res_id" />
</group>
<group string="Error" attrs="{'invisible': [('error', '=', False)]}">
<field name="error" nolabel="1" />
<field name="error" nolabel="1" colspan="4" />
</group>
<group string="Data">
<field name="data_display" nolabel="1" />
<field
name="data_display"
nolabel="1"
colspan="4"
widget="ace"
options="{'mode': 'python'}"
/>

</group>
</form>
</field>
Expand Down
22 changes: 22 additions & 0 deletions connector_search_engine/views/se_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button
name="action_open_bindings"
type="object"
class="oe_stat_button"
icon="fa-list-ul"
context="{'search_default_groupby_state': 1}"
>

<div class="o_stat_info">
<field name="count_all" class="o_stat_value" />
<span
class="o_stat_text"
attrs="{'invisible': [('count_all', '&lt;', 2)]}"
> Bindings</span>
<span
class="o_stat_text"
attrs="{'invisible': [('count_all', '&gt;', 1)]}"
> Binding</span>
</div>
</button>
</div>
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" class="oe_inline" required="1" />
Expand Down
1 change: 1 addition & 0 deletions connector_search_engine/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import se_binding_state_updater
19 changes: 19 additions & 0 deletions connector_search_engine/wizards/se_binding_state_updater.py
Original file line number Diff line number Diff line change
@@ -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})
33 changes: 33 additions & 0 deletions connector_search_engine/wizards/se_binding_state_updater.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="se_binding_state_updater_form_view">
<field
name="name"
>se.binding.state.updater.form (in connector_search_engine)</field>
<field name="model">se.binding.state.updater</field>
<field name="arch" type="xml">
<form string="Se Binding State Updater">
<group>
<field name="state" />
</group>
<footer>
<button name="doit" string="OK" class="btn-primary" type="object" />
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_record_bind" model="ir.actions.act_window">
<field name="name">Update state</field>
<field name="res_model">se.binding.state.updater</field>
<field name="view_mode">form</field>
<field name="view_id" ref="se_binding_state_updater_form_view" />
<field name="target">new</field>
<field name="binding_model_id" ref="connector_search_engine.model_se_binding" />
</record>

</odoo>

0 comments on commit 2399680

Please sign in to comment.