Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
6609 Vistas

Hi

I'm working with a report in RML, and data table of pos_order.
Using date_order field is set to 'timestamp' format.

Use the following format for the day, month, year:

 

datetime.datetime.strptime(pos_order.date_order, DEFAULT_SERVER_DATE_FORMAT).strftime('%d/%m/%Y')

but without result.

Another solution?

Thank You.

This is a snippet of my code:

report.py

def get_pos_data(self, form):
        pos_order_obj = self.pool.get('pos.order')
        pos_order_id = pos_order_obj.search(self.cr, self.uid, [
                                                             ('date_order','>=', period.date_start),
                                                             ('date_order','<=', period.date_stop)])
        pos_order_list = []
        for pos_order in pos_order_obj.browse(self.cr, self.uid, pos_order_id):
            res = {
                'date_pos' : time.strftime('%d') + '-' + datetime.strptime(pos_order.date_order, '%d-%m-%Y').strftime('%b').upper() + '-' + time.strftime('%Y')
            }
            pos_order_list.append(res)
        return pos_order_list

report.rml

<para style="P4">[[ obj['date_pos'] ]]</para>

Avatar
Descartar
Mejor respuesta

Your field is in string format containing date in a format different from DEFAULT_SERVER_DATE_FORMAT. As I can understand from the "report.py" your field is in format "%d-%b-%Y" where the month will be converted to uppercase. Either change the format of the field in the 'report.py' or change the format string that you pass to strptime

Avatar
Descartar
Autor Mejor respuesta

Thank You Jordan Vrtanoski.

struct_time_convert = time.strptime(pos_order.date_order, '%Y-%m-%d %H:%M:%S')

date_time_convert = datetime.fromtimestamp(mktime(struct_time_convert))

date = date_time_convert.strftime('%d/%m/%Y')

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 24
8535
0
abr 17
3223
1
abr 17
4598
2
nov 15
4958
0
mar 15
4711