Skip to content

Commit

Permalink
[FIX] base_name_search_improved: don't patch abstract models
Browse files Browse the repository at this point in the history
When applying monkey patches, we want to skip abstract models because patching
those may mess up the inheritance. An example of this is ir.model which is
assigned the studio mixin using inherit = ['studio.mixin', 'ir.model'].
If the mixin itself is patched, and the method is overridden once again (in,
say, enterprise 15's documents_spreadsheet), the super() method called in that
override is the patched version of studio.mixin rather than the override of
ir.model in the base module, which is now skipped entirely.
  • Loading branch information
StefanRijnhart authored and lef-adhoc committed Nov 26, 2024
1 parent 53af04f commit eb28deb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions base_name_search_improved/models/ir_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,25 @@ def check_name_search_domain(self):
raise ValidationError(_("Name Search Domain must be a list of tuples"))

def _register_hook(self):

"""Apply monkey patches.
Patch `fields_view_get` on the base model, and a freshly generated copy
of `_name_search` on each concrete model.
We want to skip abstract models because patching those may mess up the
inheritance. An example of this is `ir.model` which is assigned the
studio mixin using `inherit = ['studio.mixin', 'ir.model']`.
If the mixin itself is patched, and the method is overridden once again
(in, say, enterprise's `documents_spreadsheet`), the super() method
called in that override is the patched version of `studio.mixin` rather
than the override of `ir.model` in the base module, which is now skipped
entirely.
"""
_logger.info("Patching BaseModel for Smart Search")

for model in self.sudo().search(self.ids or []):
Model = self.env.get(model.model)
if Model is not None:
if Model is not None and not Model._abstract:
Model._patch_method("_name_search", patch_name_search())

return super()._register_hook()

0 comments on commit eb28deb

Please sign in to comment.