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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
# 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 ModelSingleton, ModelSQL, ModelView, fields
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.pool import Pool
from trytond.pyson import Eval, Id
tax_roundings = [
('document', 'Per Document'),
('line', 'Per Line'),
]
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
'Account Configuration'
__name__ = 'account.configuration'
default_account_receivable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Receivable",
domain=[
('closed', '!=', True),
('type.receivable', '=', True),
('party_required', '=', True),
('company', '=', Eval('context', {}).get('company', -1)),
]))
default_account_payable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Payable",
domain=[
('closed', '!=', True),
('type.payable', '=', True),
('party_required', '=', True),
('company', '=', Eval('context', {}).get('company', -1)),
]))
default_customer_tax_rule = fields.MultiValue(fields.Many2One(
'account.tax.rule', "Default Customer Tax Rule",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
('kind', 'in', ['sale', 'both']),
],
help="Default customer tax rule for new parties."))
default_supplier_tax_rule = fields.MultiValue(fields.Many2One(
'account.tax.rule', "Default Supplier Tax Rule",
domain=[
('company', '=', Eval('context', {}).get('company', -1)),
('kind', 'in', ['purchase', 'both']),
],
help="Default supplier tax rule for new parties."))
tax_rounding = fields.MultiValue(fields.Selection(
tax_roundings, "Tax Rounding"))
reconciliation_sequence = fields.MultiValue(fields.Many2One(
'ir.sequence', "Reconciliation Sequence", required=True,
domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('sequence_type', '=',
Id('account',
'sequence_type_account_move_reconciliation')),
]))
currency_exchange_journal = fields.MultiValue(fields.Many2One(
'account.journal', "Currency Exchange Journal",
domain=[
('type', '=', 'write-off'),
]))
currency_exchange_credit_account = fields.MultiValue(fields.Many2One(
'account.account', "Currency Exchange Credit Account",
domain=[
('closed', '!=', True),
('type.statement', '=', 'income'),
('company', '=', Eval('context', {}).get('company', -1)),
('second_currency', '=', None),
]))
currency_exchange_debit_account = fields.MultiValue(fields.Many2One(
'account.account', "Currency Exchange Debit Account",
domain=[
('closed', '!=', True),
('type.statement', '=', 'income'),
('company', '=', Eval('context', {}).get('company', -1)),
('second_currency', '=', None),
]))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field in {
'default_account_receivable', 'default_account_payable',
'currency_exchange_credit_account',
'currency_exchange_debit_account'}:
return pool.get('account.configuration.default_account')
if field in {'default_customer_tax_rule', 'default_supplier_tax_rule'}:
return pool.get('account.configuration.default_tax_rule')
if field == 'reconciliation_sequence':
return pool.get('account.configuration.sequence')
elif field == 'currency_exchange_journal':
return pool.get('account.configuration.journal')
return super(Configuration, cls).multivalue_model(field)
@classmethod
def default_tax_rounding(cls, **pattern):
return cls.multivalue_model('tax_rounding').default_tax_rounding()
@classmethod
def default_reconciliation_sequence(cls, **pattern):
return cls.multivalue_model(
'reconciliation_sequence').default_reconciliation_sequence()
@classmethod
def default_currency_exchange_journal(cls, **pattern):
return cls.multivalue_model(
'currency_exchange_journal').default_currency_exchange_journal()
class ConfigurationDefaultAccount(ModelSQL, CompanyValueMixin):
"Account Configuration Default Account"
__name__ = 'account.configuration.default_account'
default_account_receivable = fields.Many2One(
'account.account', "Default Account Receivable",
domain=[
('type.receivable', '=', True),
('party_required', '=', True),
('company', '=', Eval('company', -1)),
])
default_account_payable = fields.Many2One(
'account.account', "Default Account Payable",
domain=[
('type.payable', '=', True),
('party_required', '=', True),
('company', '=', Eval('company', -1)),
])
currency_exchange_credit_account = fields.Many2One(
'account.account', "Currency Exchange Credit Account",
domain=[
('closed', '!=', True),
('type.statement', '=', 'income'),
('company', '=', Eval('company', -1)),
('second_currency', '=', None),
])
currency_exchange_debit_account = fields.Many2One(
'account.account', "Currency Exchange Debit Account",
domain=[
('closed', '!=', True),
('type.statement', '=', 'income'),
('company', '=', Eval('company', -1)),
('second_currency', '=', None),
])
class DefaultTaxRule(ModelSQL, CompanyValueMixin):
"Account Configuration Default Tax Rule"
__name__ = 'account.configuration.default_tax_rule'
default_customer_tax_rule = fields.Many2One(
'account.tax.rule', "Default Customer Tax Rule",
domain=[
('company', '=', Eval('company', -1)),
('kind', 'in', ['sale', 'both']),
])
default_supplier_tax_rule = fields.Many2One(
'account.tax.rule', "Default Supplier Tax Rule",
domain=[
('company', '=', Eval('company', -1)),
('kind', 'in', ['purchase', 'both']),
])
class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin):
'Account Configuration Tax Rounding'
__name__ = 'account.configuration.tax_rounding'
configuration = fields.Many2One('account.configuration', 'Configuration',
required=True, ondelete='CASCADE',
context={
'company': Eval('company', -1),
},
depends={'company'})
tax_rounding = fields.Selection(tax_roundings, 'Method', required=True)
@classmethod
def default_tax_rounding(cls):
return 'document'
class Sequence(ModelSQL, CompanyValueMixin):
"Account Configuration Sequence"
__name__ = 'account.configuration.sequence'
reconciliation_sequence = fields.Many2One(
'ir.sequence', "Reconciliation Sequence", required=True,
domain=[
('company', 'in', [Eval('company', -1), None]),
('sequence_type', '=',
Id('account', 'sequence_type_account_move_reconciliation')),
])
@classmethod
def default_reconciliation_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id(
'account', 'sequence_account_move_reconciliation')
except KeyError:
return None
class Journal(ModelSQL, CompanyValueMixin):
"Account Configuration Journal"
__name__ = 'account.configuration.journal'
currency_exchange_journal = fields.Many2One(
'account.journal', "Currency Exchange Journal",
domain=[
('type', '=', 'write-off'),
],
context={
'company': Eval('company', -1),
})
@classmethod
def default_currency_exchange_journal(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('account', 'journal_currency_exchange')
except KeyError:
return None
|