This question has been flagged
3 Replies
7392 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?

Avatar
Discard
Best Answer

I think you need to first set the language.

 <para style="terp_default_8">[[ setLang(o.partner_id.lang) ]]</para>
Avatar
Discard
Author Best Answer

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

Avatar
Discard
Best Answer

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!

Avatar
Discard