我想输出本地化格式但没有时间的odoo 8日期时间字段。如何在Qweb报表上无时间输出odoo 8 datetime字段?
我使用选项hide_time
扩展了t-field
。 是否有更简单的内置解决方案?
我想输出本地化格式但没有时间的odoo 8日期时间字段。如何在Qweb报表上无时间输出odoo 8 datetime字段?
我使用选项hide_time
扩展了t-field
。 是否有更简单的内置解决方案?
你可以尝试在t-field-options
指定格式,像这样的:只要你想
<span t-field="object.datetimefield" t-field-options='{"format": "MMMM d y"}'/>
只是调整格式。
您可以使用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
我刚刚遇到这个问题,现在可以用简单的方法来完成。根据打印报告的用户,除了保留日期的相应格式lang外,这种方式仅显示没有时间的日期。
<p t-field="o.your_datetime_field" t-field-options='{"widget": "date"}'/>
警告:的的t-field-options
报价必须是完全一样,我写,否则,该行不会起作用。
希望它有助于未来任何需要此功能的人。
这是最简单和最灵活的选择。在Odoo 9中表现出色。谢谢! – travisw
您可以使用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>
您可以使用以下方法:
<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
这似乎并不能保留本地化的选择。 –
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