跳至內容
選單
此問題已被標幟
2 回覆
6606 瀏覽次數

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>

頭像
捨棄
最佳答案

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

頭像
捨棄
作者 最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
7月 24
8535
0
4月 17
3223
1
4月 17
4598
2
11月 15
4957
0
3月 15
4711