Odoo Help


how to do search method compare currentdate with str format date field

on 5/6/13, 7:00 AM 4,133 views

search method compare of current date which is date format with date_open is crm_lead field which is string format how to do that

def get_name(self, form):       
    crm_obj = self.pool.get('crm.lead')
    d = datetime.now().date()
    line=crm_obj.browse(self.cr, self.uid, self.ids)
    for val in line:
        cdate=datetime.strptime(nameop,'%Y-%m-%d %H:%M:%S').date()                      
    print type(nameop),cdate,type(cdate),gval,cur_date,targetselect,d,"hhhhhhhhhhhhhhhhhhhhhhhhhhh"
    if targetselect=='daily':
        print cdate,d,"111111111111111111111111111111"          
        lines=crm_obj.search(self.cr, self.uid, [('date_open','==',d)])
        print lines
        raise osv.except_osv(_('Info'),_('There is no entry for today'))    
        print x

So what is the issue?

Sudhir Arya (SA)
on 5/6/13, 7:22 AM

lines=crm_obj.search(self.cr, self.uid, [('date_open','==',d)]) if i do that error gives as object of type 'datetime.date' has no len() date_open-->string of date time field and d->currentdate

on 5/6/13, 7:36 AM

date_open is a datetime type or only date type?

Sudhir Arya (SA)
on 5/6/13, 7:43 AM

date_open is a string type and time.strftime("%Y-%m-%d") is a datetime.date type, will the compare happen(i check your updated code it still loading the web page no result produced)

on 5/6/13, 7:51 AM

Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 5/6/13, 7:45 AM

If date_open is date type field:

lines = crm_obj.search(self.cr, self.uid, [('date_open','=',time.strftime("%Y-%m-%d"))])

If date_open is datetime type field:

d = datetime.now().date()
#Convert date type from datetime.date type into string
d1 = datetime.strftime(d, "%Y-%m-%d %H:%M:%S")
d2 = datetime.strftime(d, "%Y-%m-%d 24:59:59")
lines = crm_obj.search(self.cr, self.uid, [('date_open','>=',d1), ('date_open','<=',d2)])

You have to search it between current date+start time of the day (2013-05-06 00:00:00) and current date+end time of the day (2013-05-06 24:59:59) because you have date as datetime.

See my updated code. It will work.

Sudhir Arya (SA)
on 5/6/13, 8:31 AM

you really great it's working fine arya i have a another one how to browse all user record , if i browse record only i can get who entered, a lot of thanks to you

on 5/6/13, 10:47 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

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.


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

0 follower(s)


Asked: 5/6/13, 7:00 AM
Seen: 4133 times
Last updated: 3/16/15, 8:10 AM