Skip to content

Commit

Permalink
Merge PR #163 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 bb948a4 + 708edc4 commit e56303c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
6 changes: 3 additions & 3 deletions connector_search_engine/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Connector Search Engine
=======================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down Expand Up @@ -177,15 +177,15 @@ Changelog
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. (`#162 <https://github.com/OCA/search-engine/issues/162>`_)
*Search Engine Backend* and *Search Engine Record* views. (`#162 <https://github.com/OCA/search-engine/issues/162>`__)


**Bugfixes**

- 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. (`#162 <https://github.com/OCA/search-engine/issues/162>`_)
Makes the Odoo's admin user a member of the *Search Engine Connector Manager* group. (`#162 <https://github.com/OCA/search-engine/issues/162>`__)


12.0.x.y.z (YYYY-MM-DD)
Expand Down
35 changes: 35 additions & 0 deletions connector_search_engine/models/se_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import json
import logging
from collections import defaultdict
from typing import Any, Dict, Iterator

from typing_extensions import Self

from odoo import _, api, fields, models, tools
from odoo.exceptions import ValidationError

Expand Down Expand Up @@ -201,3 +204,35 @@ def recompute_from_owner(self):
)
bindings.write({"state": "recomputing"})
bindings.jobify_recompute_json()

@api.model_create_multi
def create(self, vals_list) -> Self:
"""Create a binding and compute its JSON."""
records = super().create(vals_list)
records._invalidate_bindings_in_references()
return records

def write(self, vals) -> bool:
"""Write a binding and compute its JSON."""
if "res_model" in vals or "res_id" in vals:
# invalidate bindings in current references
self._invalidate_bindings_in_references()
res = super().write(vals)
if "res_model" in vals or "res_id" in vals:
# invalidate bindings in new references
self._invalidate_bindings_in_references()
return res

def unlink(self):
self._invalidate_bindings_in_references()
return super().unlink()

def _invalidate_bindings_in_references(self):
"""Invalidate the binding_ids field on the records referenced by the
bindings.
"""
ids_by_model = defaultdict(list)
for binding in self:
ids_by_model[binding.res_model].append(binding.res_id)
for model, ids in ids_by_model.items():
self.env[model].browse(ids).invalidate_recordset(["se_binding_ids"])
6 changes: 3 additions & 3 deletions connector_search_engine/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def _compute_count_binding(self):
groupby=["index_id", "state"],
lazy=False,
)
all = 0
_all = 0
for item in data:
count = item["__count"]
res[item["index_id"][0]][item["state"]] = count
all += count
_all += count

def get(index_id, states):
return sum([res[index_id][state] for state in states])
Expand All @@ -93,7 +93,7 @@ def get(index_id, states):
],
)
record.count_error = get(record.id, ["invalid_data", "recompute_error"])
record.count_all = all
record.count_all = _all
if record.count_error:
record.color = 1
elif record.count_pending:
Expand Down
4 changes: 2 additions & 2 deletions connector_search_engine/readme/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
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. (`#162 <https://github.com/OCA/search-engine/issues/162>`_)
*Search Engine Backend* and *Search Engine Record* views. (`#162 <https://github.com/OCA/search-engine/issues/162>`__)


**Bugfixes**

- 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. (`#162 <https://github.com/OCA/search-engine/issues/162>`_)
Makes the Odoo's admin user a member of the *Search Engine Connector Manager* group. (`#162 <https://github.com/OCA/search-engine/issues/162>`__)


12.0.x.y.z (YYYY-MM-DD)
Expand Down
5 changes: 5 additions & 0 deletions connector_search_engine/readme/newsfragments/163.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixes cache issue with the *se_binding_ids* field on the *s.indexable.record*
model. When a binding is created or updated or deleted, the cache for the
*se_binding_ids* field for referenced records is now invalidated. That way,
the next time the field is accessed after such an operation, the value is
recomputed to reflect the change.
7 changes: 7 additions & 0 deletions connector_search_engine/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,10 @@ def test_life_cycle(self):
kwargs={},
)
self.assertFalse(self.partner_binding.exists())

def test_binding_ids_on_record(self):
self.assertEqual(self.partner.se_binding_ids, self.partner_binding)
self.partner_binding.unlink()
self.assertFalse(self.partner.se_binding_ids)
partner_binding = self.partner._add_to_index(self.se_index)
self.assertEqual(self.partner.se_binding_ids, partner_binding)

0 comments on commit e56303c

Please sign in to comment.