How can I format a date in an Odoo 8 QWeb report?

The date on my sales order is currently displayed as:

Fecha: 21/11/2014 16:59:15 

I want to show something like this:

 Fecha: Surco, 21 de Noviembre del 2014 

I tried using t-esc with strftime , but this does not work:

 <span t-esc="o.date_order.strftime('%Y')" /> 
+8
openerp report qweb
source share
3 answers

It seems that o.date_order is not a datetime object, but a string. Using the time module is the way to go:

 <span t-esc="time.strftime('%A, %d %B %Y',time.strptime(o.date_order,'%Y-%m-%d %H:%M:%S'))"/> 
+8
source share

Try using:

 <span t-field="o.date_order" t-field-options='{"format": "d MMMM y"}'/> 

Result: November 21, 2014

+17
source share

Listen up. You can also set a custom date form using the function

Add function to your_report.py file

 class member_branch_mov(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(member_branch_mov, self).__init__(cr, uid, name, context) self.localcontext.update({ 'time': time, 'get_formate_header_date':self._get_formate_header_date }) def _get_formate_header_date(self, objects): header_date='' if self.end_date: date = datetime.strptime(self.end_date,'%Y-%m-%d') header_date=date.strftime('%d %B %Y') return header_date.upper() 

hear self.end_date comes from the wizard field

Add your_report_view.xml to your report

  <t t-if="get_formate_header_date(docs)"><span t-esc="get_formate_header_date(docs)" /></t> 
0
source share

All Articles