Reputation: 5044
How to add current date in email template so that current date will be showed in the mail? Also how can we change the date format to be displayed?
Upvotes: 2
Views: 3027
Reputation: 181
In OpenERP/Odoo email template,
You could add javascript to compute your current date.
<script language="javascript">
var today = new Date();
document.getElementById('time').innerHTML=today;
</script>
and call this value by using
<p id="time"></p>
Note: I obtained this info from another question. Link here
Upvotes: 1
Reputation: 2393
email_templates
use 'jinja' template engine. The bad news for lazy people like us is that jinja
doesn't support inline python. You have only access to variables passed to the template at render time.
One of this variable is object
and represents the object you attach to the template, let say res_partner
. What you can try is to extend res_partner
and add a field which calculates the current date. Something like this:
from openerp.osv import fields, Model
class res_partner(osv.Model):
"""Inherit res.partner to add a generic field that can be used
to in email templates."""
_inherit = 'res.partner'
def _get_now(self, cr, uid, ids, field_name, arg, context):
from datetime import datetime
return datetime.now()
_columns = {
'current_date_time': fields.function(_get_now, type="char",
method=True, store=False)
}
res_partner()
Now you should be able to put in your template this:
${object.current_date_time}
I didn't test it. Let me know if it works if you try it.
Upvotes: 1