Skip to content

Commit 21bbd15

Browse files
author
bosd
committed
Fixupsgit add .
1 parent f8f0f68 commit 21bbd15

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

base_sparse_field_jsonb_search/models/base_model.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ class Base(models.AbstractModel):
4545

4646
_inherit = "base"
4747

48-
def _where_calc(self, domain, active_test=True):
48+
def _search(
49+
self,
50+
domain,
51+
offset=0,
52+
limit=None,
53+
order=None,
54+
*,
55+
active_test=True,
56+
bypass_access=False,
57+
):
4958
"""Override to translate sparse field domains to JSONB operators.
5059
5160
This method intercepts the domain before it's processed by the ORM
5261
and translates any sparse field references to native PostgreSQL
5362
JSONB operators for efficient querying.
63+
64+
Note: In Odoo 19, _where_calc was replaced by _search.
5465
"""
5566
# Get mapping of sparse fields to their containers
5667
sparse_fields = self._get_sparse_field_mapping()
@@ -59,10 +70,15 @@ def _where_calc(self, domain, active_test=True):
5970
# Transform domain to use JSONB operators for sparse fields
6071
domain = self._transform_jsonb_domain(domain, sparse_fields)
6172

62-
# Call the original _where_calc from models.BaseModel
63-
from odoo.models import BaseModel
64-
65-
return BaseModel._where_calc(self, domain, active_test=active_test)
73+
# Call parent _search
74+
return super()._search(
75+
domain,
76+
offset=offset,
77+
limit=limit,
78+
order=order,
79+
active_test=active_test,
80+
bypass_access=bypass_access,
81+
)
6682

6783
@api.model
6884
def _get_sparse_field_mapping(self):

base_sparse_field_jsonb_search/tests/test_jsonb_search.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,27 @@ def test_transform_jsonb_domain_list_leaf(self):
134134
result = self.Base._transform_jsonb_domain(domain, {})
135135
self.assertEqual(result, domain)
136136

137-
def test_where_calc_no_sparse_fields(self):
138-
"""Test _where_calc works normally without sparse fields."""
137+
def test_search_no_sparse_fields(self):
138+
"""Test _search works normally without sparse fields."""
139139
# This should not raise any errors
140-
query = self.Partner._where_calc([("name", "=", "test")])
140+
query = self.Partner._search([("name", "=", "test")])
141141
self.assertIsNotNone(query)
142142

143-
def test_where_calc_empty_domain(self):
144-
"""Test _where_calc with empty domain."""
145-
query = self.Partner._where_calc([])
143+
def test_search_empty_domain(self):
144+
"""Test _search with empty domain."""
145+
query = self.Partner._search([])
146146
self.assertIsNotNone(query)
147147

148-
def test_where_calc_complex_domain(self):
149-
"""Test _where_calc with complex domain."""
148+
def test_search_complex_domain(self):
149+
"""Test _search with complex domain."""
150150
domain = [
151151
"&",
152152
("name", "ilike", "test"),
153153
"|",
154154
("active", "=", True),
155155
("comment", "!=", False),
156156
]
157-
query = self.Partner._where_calc(domain)
157+
query = self.Partner._search(domain)
158158
self.assertIsNotNone(query)
159159

160160

0 commit comments

Comments
 (0)