Odoo Help

1

How to compare a string and a datetime in a search domain ?

By
Tatorus
on 3/10/16, 6:17 AM 2,983 views

Hi, i have to select in idProd the products who respect those conditions :

idProd = product_product.search([('product_tmpl_id.ing', '=', True), ('product_tmpl_id.last_synchro_ing', '<', date)], order='id')


The problem is for the sample in bold because "product_tmpl_id.last_synchro_ing" is a string and "date" is a datetime.

So I don't know how to compare them in a search domain, thanks in advance.

1
Motez
On 3/11/16, 6:38 AM

You need to convert your datetime object to a string so postgre can handle it. use the strftime method

idProd = product_product.search([('product_tmpl_id.ing', '=', True),
('product_tmpl_id.last_synchro_ing', '<', date.strftime("%Y-%m-%d"))
], order='id')

0

Damien Bouvy (dbo)

--Damien Bouvy (dbo)--

2010
| 1 0 1
Grand-Rosière, Belgium
--Damien Bouvy (dbo)--

Damien is part of the Odoo R&D department. He has taken part in the development of several features in Odoo, including the Subscription application, the Sales application, the frontend portal and the payment acquirers.

Nowadays he commits on our internal codebase, maintaining the billing process of Odoo.com, developing external tools and internal processes. More recently, he took part in the development of the Odoo.sh platform.

Damien Bouvy (dbo)
On 3/16/16, 6:16 PM

Hi,

There are also helper functions on the fields.Date model:

 
def from_string(value):
     """ Convert an ORM ``value`` into a :class:`date` value. """
def to_string(value):
     """ Convert a :class:`date` value into the format expected by the ORM. """

So you could do

idProd = product_product.search([('product_tmpl_id.ing', '=', True), ('product_tmpl_id.last_synchro_ing', '<', fields.Date.to_string(date))], order='id')

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 3/10/16, 6:17 AM
Seen: 2983 times
Last updated: 4/19/16, 4:24 PM