コンテンツへスキップ
メニュー
この質問にフラグが付けられました
11 返信
9575 ビュー

I changed date format from Languages ,then its change in odoo interface.But in Reports its coming in different format need a help..

Attached screen shots  


This is for reports screen shots-----

http://prntscr.com/ixyq6s


Language (odoo )screenshot --

http://prntscr.com/ixyr0a

Required format is mm/dd/yy but in reports yy/mm/dd

How i can solve this issue?

アバター
破棄
最善の回答

Hi,

First you need to find user’s language date format like as follows,

user_date_format = self.env['res.lang']._lang_get(self.env.user.lang).date_format


Then use the following line to change your fields in report


date_from = datetime.strptime(str(self.date_from), '%Y-%m-d').strftime(str(user_date_format))
date_to = datetime.strptime(str(self.date_to), '%Y-%m-%d').strftime(str(user_date_format))


Regards

アバター
破棄
最善の回答

H e llo 

You Need To Change It Manually from Report XML Code,

So First You Have Inherit That Report And Using Xpath You Have To Add Attribute For Particular Format of Date That You Want.


Because Changes You Have That Only For Odoo View, For Report You Must Have Inherit The Report and Apply Changes. 


For Example


< span t-field = "field_name" t-field-options = '{"format": "Mdy"}' />



アバター
破棄
著作者

Need to manually change whole reports?

No You Have to Inherit Report And Change only Particular That Date Field. or You can Replace That Date Field With New One.

著作者

okay..

最善の回答

By default it should be converted automatically according to the language setting of the related partner. If the language of the partner is not set, it is set to the language setting of the user.

アバター
破棄
著作者

Language of partner already set as English..and format is dd-mm-yy

著作者

you are talking about by prefernce menu right?

最善の回答

First of all you need to converting datetime.date to datetime.datetime

start_date = datetime.strptime(s_date.strftime('%Y%m%d'), '%Y%m%d')

Date formatting in Qweb reports (dd-mm-yy):

<h5 class="pull-right" style="position:relative; top: 2px; margin:0;"><u>Printed Date: <span t-esc="time.strftime('%d-%b-%Y')"></span></u></h5>

For more detail visit: http://learnopenerp.blogspot.com/2016/09/how-to-convert-datetimedate-to.html

アバター
破棄
著作者

But i am not talking about a single report.Like i need to change in whole report without chnage each field date format