Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
11 Vastaukset
9893 Näkymät

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?

Avatar
Hylkää
Paras vastaus

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

Avatar
Hylkää
Paras vastaus

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"}' />



Avatar
Hylkää
Tekijä

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.

Tekijä

okay..

Paras vastaus

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.

Avatar
Hylkää
Tekijä

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

Tekijä

you are talking about by prefernce menu right?

Paras vastaus

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

Avatar
Hylkää
Tekijä

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