2014-11-14 19 views

回答

5

你可以尝试在t-field-options指定格式,像这样的:只要你想

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

只是调整格式。

+2

这似乎并不能保留本地化的选择。 –

+0

Ups,我没有注意到它。也许这可以帮助:https://www.odoo.com/es_ES/forum/help-1/question/how-output-a-odoo-8-datetime-field-without-time-on-a-qweb-report -67948 – qatz

0

您可以使用formatLang<t-esc="formatLang(o.your_datatime_field,date=True)"/>

但你需要重写报告,在此示例代码:

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

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 

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

3

我刚刚遇到这个问题,现在可以用简单的方法来完成。根据打印报告的用户,除了保留日期的相应格式lang外,这种方式仅显示没有时间的日期。

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

警告:的的t-field-options报价必须是完全一样,我写,否则,该行不会起作用。

希望它有助于未来任何需要此功能的人。

+0

这是最简单和最灵活的选择。在Odoo 9中表现出色。谢谢! – travisw

0

您可以使用QWeb选项(t-field-options)。例如:

<div class="col-xs-6 text-center report-field"> 
    <span t-field="ph_id.image_date" t-field-options='{"format":"d MMMM y"}'/> 
</div> 
0

您可以使用以下方法:

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

原始日期字段:

2017年1月15日10时41分01秒

输出日期字段:

01/15/2017