Help

2

Timezone date field Email Template.

Avatar
Gustavo

I have a little problem with an email template, I include within body_html datetime field, at the time of sending the mail that arrives with the wrong date (over 5 hours) I guess that is the issue of time zones; I have no idea how I can specify in the mail template that should take the user's time zone, I have seen that to address this in the reports with "Aeroo reports" is enclosed in <formatLang(o.f_start, date_time=True)> but for the case of the mail template does not work.

What I can think of at the moment is to create a functional field that returns me the date converted to the time zone of the user but do not think is the most correct way to solve this problem.

I thank you so much any help on the subject.

2 Comments
Avatar
Discard
Avatar
Niels Huylebroeck
-

Not only is the timestamp wrong, it will also use the default formatting (YYYY-MM-DD) instead of the chosen language's format. See also this question : http://help.openerp.com/question/17559/what-is-the-syntax-to-round-numbers-in-the-email-templates/ which is about numbers and getting them formatted correctly.

Avatar
Niels Huylebroeck
-

Another search yielded me : http://help.openerp.com/question/15885/how-to-change-email-templates-date-format/

1 Answer
1
Avatar
krishnakanth
Best Answer

Hi Gustavo,

Can you try this once as follows:

${format_tz(object.date_order, tz=user.tz, context={'lang':object.partner_id.lang})}

As per your email template as follows:

${format_tz(object.f_start, tz=user.tz, context={'lang':object.partner_id.lang})}

Only Date time value:

${format_tz(object.date_order)}

1 Comment
Avatar
Discard
Avatar
Magen
-

Looking at the code of format_tz it till take use_babel = True in order to translate to the right language. But how can I change context in email template since format_tz() uses: env.context.get('use_babel') the context is no longer being passed as an argument.

I tried: self.with_context(use_babel=True).format_tz(... but self is not available. Neither object.with_context(use_babel=True).format_tz(... works because format_tz() is not a child of object