Odoo Help

7
20 Answers
7
Vince Vinet
8/22/14, 1:20 PM

There is the email_template_dateutil module in OCA/server-tools:

https://github.com/OCA/server-tools/tree/7.0/email_template_dateutil

This module adds the format_date filter in the email template environment, and can be used like this:

${object.date_invoice|format_date("%m/%d/%Y")}

${object.some_datetime|format_date()}

This will use the current user's timezone by default, or the server timezone, or you can pass in your own timezone.

1 Comment
Arche TI, Marc Cassuto
8/25/14, 10:01 AM

Module tested and it works perfectly with any date and time format !!

3
Tim Birkett
2/18/14, 12:08 PM

SIMPLE:

We Know the date format output by: ${object.date_invoice} (or any other date) in Email Templates is: YYYY-MM-DD.

We also know that Python sees the value as a string. Use the built in split() method to output each part of the date like so:

For DD-MM-YYYY formatted date:

Replace: ${object.date_invoice}

With: ${object.date_invoice.split('-')[2] + '-' + object.date_invoice.split('-')[1] + '-' + object.date_invoice.split('-')[0]}

No extending classes or writing custom modules!!

2 Comments
initOS GmbH, Torsten Francke
3/23/14, 11:55 AM

the problem with this, that you change to format. But you ignore if you are in a different timezone as UTC

Gets MSS SA, Stephane Oechslin
4/16/16, 1:28 AM

I tried the above syntx in Odoo8 and it didn't work. But the following worked nicely: ${object.x_date_livraison.split('-')[2]}/${object.x_date_livraison.split('-')[1]}/${object.x_date_livraison.split('-')[0]}

2
Avatar

Cameron

--Cameron--

1167
| 6 5 8
United Kingdom
--Cameron--
Cameron
5/23/16, 9:23 PM

I like it though... In my case Format was YYYY-MM-DD hh:mm:ss Just wanted DD-MM-YYYY So ${(object.date.split('-')[2]).split(' ')[0] + '-' + object.date.split('-')[1] + '-' + object.date.split('-')[0]}

1
Jordan Vrtanoski
12/7/14, 5:57 AM

You can find more details on the template language at http://jinja.pocoo.org/docs/dev/templates/#builtin-filters

0
Torsten Francke
8/26/13, 6:26 AM

Only editing the template is not possible to fix this. Not only the format is wrong even the timezone is alway UTC and this is confusing if your are outside UTC.

A workaround is to defined a new field as function:

    def _get_date_for_email(self, cr, uid, ids, field_name, arg, context=None):
        reads = self.browse(cr, uid, ids, context)   
        result = {}     
        for obj in reads:        
            utc = datetime.strptime(obj.date, '%Y-%m-%d %H:%M:%S').replace(tzinfo=pytz.timezone('UTC'))
            #FIXME: can we read timezone from context?            
            #if 'tz' in context:            
            #    to_zone = tz.gettz(context['tz'])
            #else:
            to_zone = tz.gettz('Europe/Berlin')
            meeting_date = utc.astimezone(to_zone)
            #TODO: Make formating here
            result[obj.id] = "%s" % meeting_date
        return result

    _columns = {
        'date_for_email' : fields.function(
            _get_date_for_email,
            type='char',
            readonly=True,
            string='Date Formated'),
    }

Maybe we need a more generic solution of this. The OpenERP Support offer me to develop a private patch but not merging to stable. I think a small community module should be the best way. So we will work on this.

7 Comments
my
11/3/13, 11:02 PM

Hallo Markus Thank you first for your trouble. At this solution, I am also interested. Sorry, but I do not know where I need to insert this code, or how I should use. Could you perhaps give here a small guide or help? Best thanks.

initOS GmbH, Torsten Francke
11/4/13, 6:48 AM

You need to extend the object which the email report is used. Like sale.order and write a addon which extends this object.

Martin T
1/13/14, 11:58 AM

Oke, how can we extend the object so the email template is using the correct date syntax?

Martin T
1/14/14, 10:14 AM

do we have to change the add-ons/email_template/email_template.py file for this?

initOS GmbH, Torsten Francke
1/15/14, 2:56 PM

No we extend the object by a openerp module, no core hacks involved

Martin T
1/15/14, 2:58 PM

Oke, can you give an example of extending an object by a openerp module?

Because I would really like, to follow the correct way.

0
Alexis de Lattre
7/11/14, 11:30 AM

I opened a bug about this on github:

https://github.com/odoo/odoo/issues/1108

0
Martin T
1/15/14, 2:58 PM

Oke, can you give an example of extending an object by a openerp module?

Because I would really like, to follow the correct way.

Ask a Question
Writer
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now