Pitfalls

This all works fine for traditional fields, but a notorious problem is searching for the value of a non-stored function field. It's a problem that people often omit the search function, while this is simple enough to fix by providing the search function in your own code as described in Chapter 5, Application Models.

Another issue that might baffle developers is Odoo's behavior when searching through one2many or many2many fields with a negative operator. Imagine that you have a partner with the A tag and you search for [('category_id.name', '!=', 'B')]. Your partner shows up in the result and this is what you expected, but if you add the B tag to this partner, it still shows up in your results, because for the search algorithm, it is enough that there is one linked record (A in this case) that does not fulfill the criterion. Now, if you remove the A tag so that B is the only tag, the partner will be filtered out. If you also remove the B tag so that the partner has no tags, it is still filtered out, because conditions on the linked records presuppose the existence of this record. In other situations though, this is the behavior you want, so it is not really an option to change the standard behavior. In case you need a different behavior here, provide a search function of your own that interprets the negation the way you need.

A small gotcha is that people forget that they are writing XML files when it is about domains. You need to escape the less-than operator. Searching for records that have been created before today will have to be [('create_date', '<', current_date)] in XML.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.91