我想輸出本地化格式但沒有時間的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