Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Set time to user's timezone in openerp 7?

By
Nick Athanasoulas
on 12/10/13, 6:06 PM 3,423 views

Hi there! I am trying to print a custom invoice. The problem is that I cannot print the user's local time. All I can is to print the in UTC Time Format. I am using the code below, but it doesn't work for displaying the time. My timezone is Europe/Athens.

I am making changes in the company's header.

Code:" <drawstring x="1cm" y="21.5cm"> [[ formatLang(time.strftime("%Y-%m-%d"), date=True) ]], Time: [[ time.strftime("%H:%M") ]]</drawstring>"

What I get: "12/10/2013, Time: 22:05" (My local time is 00:05 GMT+2)

Does anyone know how to make it work?

0

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 12/11/13, 12:57 AM

I think you need to first set the language.

 <para style="terp_default_8">[[ setLang(o.partner_id.lang) ]]</para>
0
Nick Athanasoulas
On 12/11/13, 3:57 AM

Didnt's help. Should I change something?

I just edit it like that in the companies header form. "<para style="terp_default_8">[[ setLang(o.partner_id.lang) ]]</para>

<drawstring x="1cm" y="21.5cm"> [[ formatLang(time.strftime("%Y-%m-%d"), date=True) ]], Time: [[ time.strftime("%H:%M") ]]</drawstring>"

Still nothing. Printed GMT0 time not my local one.

I also found the addon called "invoice_date_time" and extract it to /usr/share/pyshared/openerp/addons/invoice_date_time but i dont know if its right. It doesn't print the time still. It prints GMT0 time, not GMT+2. My user has timezone:Europe Athens and lang to Greek.

How can I easily make it save in the users local time? Doesn't openerp do that by default? Maybe I have forgotten to check something in settings???

the add on link: https://www.openerp.com/apps/7.0/invoice_date_time

0
Pierre verkest
On 11/28/14, 5:12 PM

I'm not sure if it's possible to use rml parser method in the header, I guess yes, it's what I did using webkit_report, I can use my parser methode in the webkit report header, which is mako format:

${displayDateTime(user.tz)}

In the parser method you can define a methode like this to return the date time you needs:

from openerp.report import report_sxw
from tools.translate import _
from datetime import datetime
from openerp.tools import misc
from osv import osv
import pytz

...

        self.localcontext.update({'test_methode': self._test_methode,
                                  'displayDateTime': self._displayDateTime,
                                  })

...

    def _displayDateTime(self, timezone, format='%d/%m/%Y %H:%M'):
        try:
            return pytz.timezone(
                misc.get_server_timezone()).localize(datetime.now()).astimezone(
                pytz.timezone(timezone)).strftime(format)
        except:
            raise osv.except_osv(_('Timezone error or date format invalid!'),
                                 _('Please set your timezone before to generate this report.') +
                                 _(' One of those values is not valid: timezone= %r - format= %r')
                                 % (timezone, format))

A bit late! hope it helps!

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 12/10/13, 6:06 PM
Seen: 3423 times
Last updated: 3/16/15, 8:10 AM