Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
12909 Lượt xem

Hi,

Can anyone tell me how to print a date in a desired format in openerp reports. I use both rml and openoffice for reporting

Default Date format in form

 12/06/2013

Default Date format while printing in reports

 2013/06/12

My Desired Format

 12-June-2013

Thanks for your time

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Write following code in report py:

import time
from datetime import datetime

'get_my_date': self.get_my_date, #Add this line in self.localcontext.update dictionary

def get_my_date(self, date):
    return time.strftime('%d') + '-' + datetime.strptime(date, '%d-%m-%Y').strftime('%b').upper() + '-' + time.strftime('%Y')

Call this method from your rml file:

<para style="P2"> [[ get_my_date(your_date) ]] </para>
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks sudir, How do i do this with regard to openoffice report i.e when i design a report in openoffice.

You can write [[ get_my_date(your_date) ]] code in sxw file also but you must have to write given method in report py file.

Tác giả

Yeah, but there's a problem in there sudir, There's a default sxw file in every module is not considered while printing. It's taken a copy when i take it and in the copy we've modified the above line and sent it to server. Nothing gets printed. Kindly guide me.

Either you can make changes in rml or first change in sxw, then convert it in rml and replace original rml with you new rml.

hi where to put 'get_my_date': self.get_my_date, code if i want to change format of date in meeting custom report in crm module

I already have written it in comment that you have to put it in "self.localcontext" in your report py file.

Câu trả lời hay nhất

If you are adding the fields through the openoffice report editor, try this:

[[ formatLang(o.date_start,date_time=True) ]] (for date + hours) or [[ formatLang(o.date_start,date=True) ]] (date)

Just replace "date_time" with your field. Take heed: this will not show it like your desired format, but it will be better than the default output.

For a better solution, follow Sudhir's instructions.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

use [[ time.strftime('%d-%B-%Y') ]]

Ảnh đại diện
Huỷ bỏ

thank you for this answer, do you know how to add customer's contact person to report ?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 24
2902
3
thg 9 20
6419
1
thg 12 24
16723
1
thg 3 15
4776
0
thg 6 24
1209