Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
22343 Vistas

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
Avatar
Descartar
Autor

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

date_open is a datetime type or only date type?

Autor

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)

Mejor respuesta

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.

Avatar
Descartar

See my updated code. It will work.

Autor

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

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

worked perfectly. Thank you.