0

According to this answer: what does attachment=True do odoo 13

When you do self.env['ir.attachment'].search([]) you do not get the records whose res_field is set, which commonly are the most part of the table, by the way.

Of course, I need to get records that do have the res_id field set. Is there a hack to do it through the ORM search?

Or do I have to do a SQL query instead? I guess many of you needed to do this once. Any good idea to respect ORM?

Kenly
  • 24,317
  • 7
  • 44
  • 60
forvas
  • 9,801
  • 7
  • 62
  • 158

2 Answers2

0

I think if you want to respect ORM, you will custom search method.

I was customed search method once, you can try

from odoo.osv import expression
    class Test():
        def search(records, domain, *args, **kwargs):
            return search.origin(records, expression.AND([[('id', '=', instance.id)], domain]), *args, **kwargs)
        self.registry['odoo.instance']._patch_method('search', search)

If you try to fail, you have to do a SQL query

Sorry,i don't learn English very well. I'm trying learn it.

0

Odoo will add res_field=False in the domain if not present (It will check if id or res_field fields are present in the domain before altering the search domain), so if you provide id or res_field Odoo will not force you to search records with res_field set to False.

The following domain should return all records in ir.attachment:

['|', ('res_field', '!=', False), ('res_field', '=',False)]
Kenly
  • 24,317
  • 7
  • 44
  • 60