Xml 如何在qweb报表上输出没有时间的odoo 8 datetime字段?
我想以本地化格式输出一个odoo 8 datetime字段,但没有时间 我使用Xml 如何在qweb报表上输出没有时间的odoo 8 datetime字段?,xml,report,odoo-8,odoo,qweb,Xml,Report,Odoo 8,Odoo,Qweb,我想以本地化格式输出一个odoo 8 datetime字段,但没有时间 我使用hide\u time选项扩展了t字段。 是否有更简单的内置解决方案?您可以尝试在t-field-options中指定格式,如下所示: 只需根据需要调整格式。您可以使用formatLang, 但您需要覆盖报告,如以下示例代码所示: ################# import time from openerp.report import report_sxw from openerp.osv impor
hide\u time
选项扩展了t字段。
是否有更简单的内置解决方案?您可以尝试在t-field-options
中指定格式,如下所示:
只需根据需要调整格式。您可以使用formatLang
,
但您需要覆盖报告,如以下示例代码所示:
#################
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
来源:我刚刚遇到了这个问题,现在可以用一种简单的方式来解决。这种方式只显示日期而不显示时间,并根据打印报告的用户保留相应的日期格式
<p t-field="o.your_datetime_field" t-field-options='{"widget": "date"}'/>
警告:t-field-options
的引号必须与我写的完全相同,否则,该行将不起作用
希望它将来能对任何需要它的人有所帮助。您可以使用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
输出日期字段:
2017年1月15日
我不知道为什么
t-field-options
不起作用,而是使用t-options
<span t-field="o.date_approve" t-options="{'widget': 'date'}" />
输出如下:
09-Jun-21
这似乎没有保留本地化选项。Ups,我没有注意到。也许这会有所帮助:这是最简单、最灵活的选择。在奥多9中效果很好。谢谢