How can I output a odoo 8 datetime field without time on a qweb report?
Asked Answered
A

6

6

I want to output a odoo 8 datetime field in the localization format but without time.

I extended the t-field with the option hide_time. Is there a simpler built-in solution?

Almeria answered 14/11, 2014 at 9:28 Comment(0)
P
5

You could try specifying a format in t-field-options, like this:

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

just adjust the format as you want.

Polyhydroxy answered 15/12, 2014 at 2:38 Comment(2)
This doesn't seem to preserve localization choices.Brockington
Ups, I didn't noticed about it. Maybe this could help : odoo.com/es_ES/forum/help-1/question/…Polyhydroxy
S
4

I have just faced this issue and now it's possible to do it in an easy way. This way shows only the date without the time in addition to keep the respective format lang of the date according to the user who printed the report.

<p t-field="o.your_datetime_field" t-field-options='{"widget": "date"}'/>

Warning: the quotes of t-field-options must be exactly like I wrote, otherwise, that line won't work.

Hope it helps in the future to anyone who needs this.

Selfdriven answered 22/10, 2015 at 8:21 Comment(2)
This is easily the simplest and most flexible option. Works great in Odoo 9. Thanks!Seiler
In Odoo 17, I need to change t-field-options to t-options, so the code will be like this <p t-field="o.your_datetime_field" t-options='{"widget": "date"}'/>Turnspit
L
0

You can use formatLang, <t-esc="formatLang(o.your_datatime_field,date=True)"/>

but you would need to override the report, as in this sample code:

################# 

import time

from openerp.report import report_sxw
from openerp.osv import osv



class QuotationPrint(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(QuotationPrint, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
        })
        self.context = context


class quotation(osv.AbstractModel):
    _name = 'report.sale.quotation_template'
    _inherit = 'report.abstract_report'
    _template = 'sale.quotation_template'
    _wrapped_report_class = QuotationPrint

Source: https://www.odoo.com/es_ES/forum/help-1/question/how-output-a-odoo-8-datetime-field-without-time-on-a-qweb-report-67948

Lishalishe answered 1/1, 2015 at 12:57 Comment(0)
D
0

You can use QWeb options (t-field-options). For example:

<div class="col-xs-6 text-center report-field">
    <span t-field="ph_id.image_date" t-field-options='{"format":"d MMMM y"}'/> 
</div>
Daina answered 7/12, 2016 at 9:56 Comment(0)
F
0

You can use the following:

<span t-esc="time.strftime('%m/%d/%Y',time.strptime(object.datetimefield,'%Y-%m-%d %H:%M:%S'))"/>

Original Date field:

01/15/2017 10:41:01

Output Date field:

01/15/2017

Feria answered 16/1, 2017 at 11:54 Comment(0)
T
0

I don't know why the t-field-options is not working, instead I use t-options.

<span t-field="o.date_approve" t-options="{'widget': 'date'}" />

the output will be like this : 09-Jun-21

Turnspit answered 23/6, 2021 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.