Commit 8e0edda 1 parent 571bc0e commit 8e0edda Copy full SHA for 8e0edda
File tree 2 files changed +36
-5
lines changed
2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 5
5
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
6
6
from odoo import _ , api , fields , models
7
7
from odoo .exceptions import ValidationError
8
+ from odoo .tools import Query
8
9
9
10
10
11
class BaseCommentTemplate (models .Model ):
@@ -128,9 +129,15 @@ def name_get(self):
128
129
129
130
def _search_model_ids (self , operator , value ):
130
131
# We cannot use model_ids.model in search() method to avoid access errors
131
- allowed_items = (
132
- self .sudo ()
133
- .search ([])
134
- .filtered (lambda x : value in x .model_ids .mapped ("model" ))
135
- )
132
+ all_items = self .sudo ().search ([])
133
+ if isinstance (value , Query ):
134
+ found_models = self .env ["ir.model" ].browse (value )
135
+ allowed_items = self .browse ()
136
+ for found_model in found_models :
137
+ model_name = found_model .model
138
+ allowed_items |= all_items .filtered (
139
+ lambda x : model_name in x .models .split ("," )
140
+ )
141
+ else :
142
+ allowed_items = all_items .filtered (lambda x : value in x .models .split ("," ))
136
143
return [("id" , "in" , allowed_items .ids )]
Original file line number Diff line number Diff line change @@ -184,3 +184,27 @@ def test_partner_commercial_fields(self):
184
184
self .assertTrue (
185
185
"base_comment_template_ids" in self .env ["res.partner" ]._commercial_fields ()
186
186
)
187
+
188
+ def test_search_model_ids_model (self ):
189
+ """Searching by "model_ids.model"
190
+ finds the comments matching the search criteria."""
191
+ # Arrange
192
+ user_ir_model = self .user_obj
193
+ user_model_name = user_ir_model .model
194
+ user_comments_by_model_ids = self .env ["base.comment.template" ].search (
195
+ [
196
+ ("model_ids" , "=" , user_model_name ),
197
+ ]
198
+ )
199
+ # pre-condition
200
+ self .assertTrue (user_comments_by_model_ids )
201
+
202
+ # Act
203
+ user_comments_by_models_path = self .env ["base.comment.template" ].search (
204
+ [
205
+ ("model_ids.model" , "=" , user_model_name ),
206
+ ]
207
+ )
208
+
209
+ # Assert
210
+ self .assertEqual (user_comments_by_model_ids , user_comments_by_models_path )
You can’t perform that action at this time.
0 commit comments