File: fields.py

package info (click to toggle)
tryton-modules-currency 7.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: python: 1,175; xml: 234; makefile: 11; sh: 3
file content (36 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download
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
# This file is part of Tryton.  The COPYRIGHT file at the toplevel of this
# repository contains the full copyright notices and license terms.
from trytond.model import fields

__all__ = ['Monetary']


class Monetary(fields.Numeric):
    """
    Define a numeric field with currency (``decimal``).
    """
    def __init__(self, string='', currency=None, digits=None, help='',
            required=False, readonly=False, domain=None, states=None,
            on_change=None, on_change_with=None, depends=None, context=None,
            loading='eager'):
        '''
        :param currency: the name of the Many2One field which stores
            the currency
        '''
        if currency:
            if depends is None:
                depends = set()
            else:
                depends = set(depends)
            depends.add(currency)
        super().__init__(string=string, digits=digits, help=help,
            required=required, readonly=readonly, domain=domain, states=states,
            on_change=on_change, on_change_with=on_change_with,
            depends=depends, context=context, loading=loading)
        self.currency = currency

    def definition(self, model, language):
        definition = super().definition(model, language)
        definition['symbol'] = self.currency
        definition['monetary'] = True
        return definition