Odoo Help

Welcome!

This community 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.

0

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

By
gpkarthick
on 5/6/13, 7:00 AM 3,944 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')
    sale_obj=self.pool.get('hr.employee')
    line=[]
    d = datetime.now().date()
    currentdate=time.strftime('%Y-%m-%d')
    cur_date=datetime.strptime(currentdate,'%Y-%m-%d')
    line=crm_obj.browse(self.cr, self.uid, self.ids)
    targetselect=form['target_selection']
    for val in line:
        nameop=val.date_open
        cdate=datetime.strptime(nameop,'%Y-%m-%d %H:%M:%S').date()                      
        gval=val.id
    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
    else:
        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

gpkarthick
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)

gpkarthick
on 5/6/13, 7:51 AM
3

Sudhir Arya (SA)

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

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

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

gpkarthick
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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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