I'd like to get a product list in Odoo 11 with several conditions by the search()
method provided in the product.product
model.
This will get a list (which contains one product with code 12345
if exist)
product_object = self.env['product.product']
product = product_object.search([('default_code', '=', '12345')])
But I want to filter the list to get products only if its update date is in the past compared to a given date. (NB: updated_at
is one of my custom fields of product.product
model, in type str
This won't work as expected:
product_object = self.env['product.product']
product = product_object.search(
['&', ('default_code', '=', '12345'), ('updated_at', '<', '2017-01-10 12:01:00')])
The product
variable always has nothing inside.
How can I search the product.product model with date as condition. Must I change my field type from string
to datetime
?
**@odoo v11 : Search method with Datetime field.**
Change your updated_at field type as Datetime
updated_at = fields.Datetime('Updated Date', required=True)
current_time = fields.Datetime.now()
product_object = self.env['product.product']
product = product_object.search([('default_code', '=', '12345'), ('updated_at', '<', current_time)])