I'm trying to search based on the value of a related field using the Odoo ORM. The related field is accessed through 2 many2one relationships:
info = env['product.supplierinfo'].search([ \
('product_tmpl_id.product_variant_id.id', '=', line.product_id.id), \
('product_tmpl_id.product_variant_id.active', '=', True), \
('x_provides_stock', '=', True), \
('x_available_qty', '>', 0)])
As you can see, the first 2 tuples in the domain are searching a field through product_tmpl_id.product_variant_id
. However, this domain does not seem to be working since I am getting many more results than I should.
If I instead add those two constraints to a filter method after the query, I get the expected results:
info = env['product.supplierinfo'].search([ \
('x_available_qty', '>', 0), \
('x_provides_stock', '=', True)]) \
.filtered(lambda i: i.product_tmpl_id.product_variant_id == line.product_id and i.product_tmpl_id.product_variant_id.active)
Is there something I'm doing wrong with the first method? The documentation says that you can use a relationship traversal through a many2one field in the domain. Is this limited to only a single many2one field?