forked from openlabs/trytond-nereid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.py
43 lines (35 loc) · 1.22 KB
/
currency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from nereid import request
__all__ = ['Currency', 'Language']
class Currency(ModelSQL, ModelView):
'''Currency Manipulation for core.'''
__name__ = 'currency.currency'
@classmethod
def convert(cls, amount):
"""A helper method which converts the amount from the currency of the
company which owns the current website to the currency of the current
session.
"""
return cls.compute(
request.nereid_website.company.currency,
amount,
request.nereid_currency
)
@classmethod
def context_processor(cls):
"""Register compute as convert template context function.
Usage:
{{ compute(from_currency, amount, to_currency, round) }}
Eg: convert
"""
return {
'compute': cls.compute,
'convert': cls.convert
}
class Language(ModelSQL, ModelView):
__name__ = "ir.lang"
default_currency = fields.Many2One(
'currency.currency', 'Default Currency'
)