跳至内容
菜单
此问题已终结
11 回复
9583 查看

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