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

Convert timestamp to date in report rml

By
Jose Vasquez
on 2/11/15, 9:44 AM 1,021 views

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>

1
Jordan Vrtanoski
On 2/11/15, 10:06 AM

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

0
Jose Vasquez
On 2/11/15, 11:06 AM

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

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

1 follower(s)

Stats

Asked: 2/11/15, 9:44 AM
Seen: 1021 times
Last updated: 3/16/15, 8:10 AM