Odoo Help


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

on 5/6/13, 7:00 AM 6,908 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 (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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

I think it should be d2 = datetime.strftime(d, "%Y-%m-%d 23:59:59")

venugopal voraganti
on 1/31/17, 2:22 AM

worked perfectly. Thank you.

GAD Group Technology, Inc., Gregory Dover
on 11/1/17, 8:36 PM

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: 6908 times
Last updated: 3/16/15, 8:10 AM