File: account.py

package info (click to toggle)
tryton-modules-account-credit-limit 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 364 kB
  • sloc: python: 378; xml: 99; makefile: 6; sh: 3
file content (52 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
# 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 ModelSQL, fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.pyson import Eval
from trytond.modules.company.model import CompanyValueMixin

__all__ = ['Configuration', 'ConfigurationDefaultCreditLimitAmount', 'Level']
default_credit_limit_amount = fields.Numeric(
    "Default Credit Limit Amount",
    help="The default credit limit amount for new customers.",
    digits=(16, Eval('default_credit_limit_amount_digits', 2)),
    depends=['default_credit_limit_amount_digits'])


class Configuration(metaclass=PoolMeta):
    __name__ = 'account.configuration'

    default_credit_limit_amount = fields.MultiValue(
        default_credit_limit_amount)
    default_credit_limit_amount_digits = fields.Function(
        fields.Integer('Currency Digits'),
        'get_default_credit_limit_amount_digits')

    def get_default_credit_limit_amount_digits(self, name):
        pool = Pool()
        Company = pool.get('company.company')
        company_id = Transaction().context.get('company')
        if company_id:
            company = Company(company_id)
            return company.currency.digits


class ConfigurationDefaultCreditLimitAmount(ModelSQL, CompanyValueMixin):
    "Account Configuration Default Credit Limit Amount"
    __name__ = 'account.configuration.default_credit_limit_amount'
    default_credit_limit_amount = default_credit_limit_amount
    default_credit_limit_amount_digits = fields.Function(
        fields.Integer("Currency Digits"),
        'on_change_with_default_credit_limit_amount_digits')

    @fields.depends('company')
    def on_change_with_default_credit_limit_amount_digits(self, name=None):
        if self.company:
            return self.company.currency.digits


class Level(metaclass=PoolMeta):
    __name__ = 'account.dunning.level'
    credit_limit = fields.Boolean('Credit Limit',
        help='Has reached the credit limit')