Files

219 lines
8.5 KiB
Python
Raw Permalink Normal View History

2014-12-02 12:54:29 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2021-12-11 17:58:41 +01:00
from trytond.model import ModelSingleton, ModelSQL, ModelView, fields
2017-04-01 00:25:49 +02:00
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
2021-12-11 17:58:41 +01:00
from trytond.pool import Pool
from trytond.pyson import Eval, Id
tax_roundings = [
('document', 'Per Document'),
('line', 'Per Line'),
]
2012-09-24 22:17:29 +02:00
2017-04-01 00:25:49 +02:00
class Configuration(
ModelSingleton, ModelSQL, ModelView, CompanyMultiValueMixin):
2012-09-24 22:17:29 +02:00
__name__ = 'account.configuration'
2017-04-01 00:25:49 +02:00
default_account_receivable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Receivable",
domain=[
('closed', '!=', True),
2019-03-24 18:00:01 +01:00
('type.receivable', '=', True),
('party_required', '=', True),
2013-10-09 18:25:04 +02:00
('company', '=', Eval('context', {}).get('company', -1)),
2017-04-01 00:25:49 +02:00
]))
default_account_payable = fields.MultiValue(fields.Many2One(
'account.account', "Default Account Payable",
domain=[
('closed', '!=', True),
2019-03-24 18:00:01 +01:00
('type.payable', '=', True),
('party_required', '=', True),
2013-10-09 18:25:04 +02:00
('company', '=', Eval('context', {}).get('company', -1)),
2017-04-01 00:25:49 +02:00
]))
2019-08-18 19:06:19 +02:00
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."))
2019-08-18 19:06:19 +02:00
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."))
2017-04-01 00:25:49 +02:00
tax_rounding = fields.MultiValue(fields.Selection(
tax_roundings, "Tax Rounding"))
2021-03-11 23:00:09 +01:00
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
2017-04-01 00:25:49 +02:00
def multivalue_model(cls, field):
pool = Pool()
if field in {
'default_account_receivable', 'default_account_payable',
'currency_exchange_credit_account',
'currency_exchange_debit_account'}:
2017-04-01 00:25:49 +02:00
return pool.get('account.configuration.default_account')
2019-08-18 19:06:19 +02:00
if field in {'default_customer_tax_rule', 'default_supplier_tax_rule'}:
return pool.get('account.configuration.default_tax_rule')
2021-03-11 23:00:09 +01:00
if field == 'reconciliation_sequence':
return pool.get('account.configuration.sequence')
elif field == 'currency_exchange_journal':
return pool.get('account.configuration.journal')
2025-04-04 00:45:18 +02:00
return super().multivalue_model(field)
@classmethod
2017-04-01 00:25:49 +02:00
def default_tax_rounding(cls, **pattern):
return cls.multivalue_model('tax_rounding').default_tax_rounding()
2021-03-11 23:00:09 +01:00
@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()
2017-04-01 00:25:49 +02:00
class ConfigurationDefaultAccount(ModelSQL, CompanyValueMixin):
__name__ = 'account.configuration.default_account'
default_account_receivable = fields.Many2One(
'account.account', "Default Account Receivable",
domain=[
('closed', '!=', True),
2019-03-24 18:00:01 +01:00
('type.receivable', '=', True),
('party_required', '=', True),
2017-04-01 00:25:49 +02:00
('company', '=', Eval('company', -1)),
])
2017-04-01 00:25:49 +02:00
default_account_payable = fields.Many2One(
'account.account', "Default Account Payable",
domain=[
('closed', '!=', True),
2019-03-24 18:00:01 +01:00
('type.payable', '=', True),
('party_required', '=', True),
2017-04-01 00:25:49 +02:00
('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),
])
2017-04-01 00:25:49 +02:00
2019-08-18 19:06:19 +02:00
class DefaultTaxRule(ModelSQL, CompanyValueMixin):
__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']),
])
2019-08-18 19:06:19 +02:00
default_supplier_tax_rule = fields.Many2One(
'account.tax.rule', "Default Supplier Tax Rule",
domain=[
('company', '=', Eval('company', -1)),
('kind', 'in', ['purchase', 'both']),
])
2019-08-18 19:06:19 +02:00
2017-04-01 00:25:49 +02:00
class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin):
__name__ = 'account.configuration.tax_rounding'
configuration = fields.Many2One('account.configuration', 'Configuration',
required=True, ondelete='CASCADE',
context={
'company': Eval('company', -1),
},
depends={'company'})
2017-04-01 00:25:49 +02:00
tax_rounding = fields.Selection(tax_roundings, 'Method', required=True)
2017-04-01 00:25:49 +02:00
@classmethod
def default_tax_rounding(cls):
return 'document'
2021-03-11 23:00:09 +01:00
class Sequence(ModelSQL, CompanyValueMixin):
__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')),
])
2021-03-11 23:00:09 +01:00
@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):
__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