-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from gisce/59452_imp_allow_mako_imports_insid…
…e_poweremail_templates Poder importar ficheros .mako en el cuerpo de la plantilla de Poweremail y nuevas variables en el scope de la plantilla
- Loading branch information
Showing
3 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import datetime | ||
import pooler | ||
|
||
|
||
class Localizer(object): | ||
def __init__(self, cursor, uid, lang): | ||
pool = pooler.get_pool(cursor.dbname) | ||
|
||
lang_o = pool.get('res.lang') | ||
lang_id = lang_o.search(cursor, uid, [('code', '=', lang)])[0] | ||
self.lang = lang_o.simple_browse(cursor, uid, lang_id) | ||
|
||
def amount(self, amount, digits=2, monetary=True): | ||
return self.lang.format('%.{}f'.format(digits), amount, monetary=monetary) | ||
|
||
def date(self, date_str): | ||
new_format = self.lang.date_format | ||
return datetime.strptime(date_str, "%Y-%m-%d").strftime(new_format) | ||
|
||
def datetime(self, datetime_str): | ||
new_format = "{} {}".format(self.lang.date_format, self.lang.time_format) | ||
return datetime.strptime(datetime_str, "%Y-%m-%d").strftime(new_format) |