From aee4fbef12a5bfe3a821e65d49f2bbdbe05304ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Fri, 8 Apr 2022 19:07:12 +0200 Subject: [PATCH] Send only the required fields when fetching a readonly view definition issue11134 review380081002 --- account.py | 165 ++++++++++++++++------------------------------- common.py | 10 ++- configuration.py | 17 ++--- fiscalyear.py | 28 +++----- journal.py | 10 ++- move.py | 92 +++++++++++--------------- move_template.py | 13 ++-- party.py | 10 +-- period.py | 12 ++-- tax.py | 65 +++++++------------ 10 files changed, 152 insertions(+), 270 deletions(-) diff --git a/account.py b/account.py index 0c0164c028..a116413df7 100644 --- a/account.py +++ b/account.py @@ -53,14 +53,12 @@ def TypeMixin(template=False): ], "Statement", states={ 'required': Bool(Eval('parent')), - }, - depends=['parent']) + }) assets = fields.Boolean( "Assets", states={ 'invisible': Eval('statement') != 'balance', - }, - depends=['statement']) + }) receivable = fields.Boolean( "Receivable", @@ -72,8 +70,7 @@ def TypeMixin(template=False): states={ 'invisible': ((Eval('statement') != 'balance') | ~Eval('assets', True)), - }, - depends=['statement', 'assets']) + }) stock = fields.Boolean( "Stock", domain=[ @@ -82,8 +79,7 @@ def TypeMixin(template=False): ], states={ 'invisible': Eval('statement') == 'off-balance', - }, - depends=['statement']) + }) payable = fields.Boolean( "Payable", @@ -95,8 +91,7 @@ def TypeMixin(template=False): states={ 'invisible': ((Eval('statement') != 'balance') | Eval('assets', False)), - }, - depends=['statement', 'assets']) + }) debt = fields.Boolean( "Debt", @@ -109,7 +104,6 @@ def TypeMixin(template=False): 'invisible': ((Eval('statement') != 'balance') | Eval('assets', False)), }, - depends=['statement', 'assets'], help="Check to allow booking debt via supplier invoice.") revenue = fields.Boolean( @@ -120,8 +114,7 @@ def TypeMixin(template=False): ], states={ 'invisible': Eval('statement') != 'income', - }, - depends=['statement']) + }) expense = fields.Boolean( "Expense", @@ -131,8 +124,7 @@ def TypeMixin(template=False): ], states={ 'invisible': Eval('statement') != 'income', - }, - depends=['statement']) + }) if not template: for fname in dir(Mixin): field = getattr(Mixin, fname) @@ -158,8 +150,7 @@ class TypeTemplate( ('statement', '!=', 'off-balance')), ), ('statement', '=', None), - ], - depends=['statement']) + ]) childs = fields.One2Many( 'account.account.type.template', 'parent', "Children") @@ -245,13 +236,11 @@ class Type( }, domain=[ ('company', '=', Eval('company')), - ], - depends=['company', 'statement']) + ]) childs = fields.One2Many('account.account.type', 'parent', 'Children', domain=[ ('company', '=', Eval('company')), - ], - depends=['company']) + ]) currency = fields.Function(fields.Many2One( 'currency.currency', 'Currency'), 'get_currency') amount = fields.Function(Monetary( @@ -268,8 +257,7 @@ class Type( help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) @classmethod def __register__(cls, module_name): @@ -508,14 +496,12 @@ def AccountMixin(template=False): states={ 'invisible': ~Eval('type'), }, - depends=['type'], help="Check to prevent posting move on the account.") reconcile = fields.Boolean( "Reconcile", states={ 'invisible': ~Eval('type'), }, - depends=['type'], help="Allow move lines of this account to be reconciled.") party_required = fields.Boolean('Party Required', @@ -526,22 +512,19 @@ def AccountMixin(template=False): ], states={ 'invisible': ~Eval('type') | ~Eval('deferral', False), - }, - depends=['type', 'deferral']) + }) general_ledger_balance = fields.Boolean('General Ledger Balance', states={ 'invisible': ~Eval('type'), }, - depends=['type'], help="Display only the balance in the general ledger report.") deferral = fields.Function(fields.Boolean( "Deferral", states={ 'invisible': ~Eval('type'), - }, - depends=['type']), + }), 'on_change_with_deferral', searcher='search_deferral') @classmethod @@ -559,13 +542,11 @@ def AccountMixin(template=False): ('id', '=', Eval('_parent_parent.%s' % type_)), ()), ] - field.depends.append('parent') cls.childs.domain.append( If(Eval(type_) & Eval('parent'), (type_, '=', Eval(type_)), ())) - cls.childs.depends.extend([type_, 'parent']) @classmethod def default_closed(cls): @@ -852,8 +833,7 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): states={ 'readonly': _states['readonly'], 'invisible': ~Eval('deferral', False), - }, - depends=['currency', 'deferral']) + }) type = fields.Many2One( 'account.account.type', "Type", ondelete='RESTRICT', states={ @@ -861,8 +841,7 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): }, domain=[ ('company', '=', Eval('company')), - ], - depends=['company']) + ]) debit_type = fields.Many2One( 'account.account.type', "Debit Type", ondelete='RESTRICT', states={ @@ -874,7 +853,6 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): domain=[ ('company', '=', Eval('company')), ], - depends=['company', 'type', 'credit_type'], help="The type used if not empty and debit > credit.") credit_type = fields.Many2One( 'account.account.type', "Credit Type", ondelete='RESTRICT', @@ -887,7 +865,6 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): domain=[ ('company', '=', Eval('company')), ], - depends=['company', 'type', 'debit_type'], help="The type used if not empty and debit < credit.") parent = fields.Many2One( 'account.account', 'Parent', select=True, @@ -903,23 +880,20 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): "Credit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_credit_debit') debit = fields.Function(Monetary( "Debit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_credit_debit') amount_second_currency = fields.Function(Monetary( "Amount Second Currency", currency='second_currency', digits='second_currency', states={ 'invisible': ~Eval('second_currency'), - }, - depends=['second_currency']), + }), 'get_credit_debit') line_count = fields.Function( fields.Integer("Line Count"), 'get_credit_debit') @@ -928,8 +902,7 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): 'account.account.deferral', 'account', "Deferrals", readonly=True, states={ 'invisible': ~Eval('type'), - }, - depends=['type']) + }) taxes = fields.Many2Many('account.account-account.tax', 'account', 'tax', 'Default Taxes', domain=[ @@ -937,23 +910,20 @@ class Account(AccountMixin(), ActivePeriodMixin, tree(), ModelSQL, ModelView): ('parent', '=', None), ], help="Default tax for manual encoding of move lines\n" - 'for journal types: "expense" and "revenue".', - depends=['company']) + 'for journal types: "expense" and "revenue".') replaced_by = fields.Many2One( 'account.account', "Replaced By", domain=[('company', '=', Eval('company', -1))], states={ 'readonly': _states['readonly'], 'invisible': ~Eval('end_date'), - }, - depends=['company']) + }) template = fields.Many2One('account.account.template', 'Template') template_override = fields.Boolean('Override Template', help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) del _states @classmethod @@ -1413,7 +1383,7 @@ class AccountParty(ActivePeriodMixin, ModelSQL): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) name = fields.Char("Name") code = fields.Char("Code") company = fields.Many2One('company.company', "Company") @@ -1436,8 +1406,7 @@ class AccountParty(ActivePeriodMixin, ModelSQL): currency='second_currency', digits='second_currency', states={ 'invisible': ~Eval('second_currency'), - }, - depends=['second_currency']), + }), 'get_credit_debit') line_count = fields.Function( fields.Integer("Line Count"), 'get_credit_debit') @@ -1635,8 +1604,7 @@ class AccountDeferral(ModelSQL, ModelView): currency='second_currency', digits='second_currency', required=True, states={ 'invisible': ~Eval('second_currency'), - }, - depends=['second_currency']) + }) line_count = fields.Integer("Line Count", required=True) second_currency = fields.Function(fields.Many2One( 'currency.currency', "Second Currency"), 'get_second_currency') @@ -1808,43 +1776,37 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView): "Start Debit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_account', searcher='search_account') debit = fields.Function(Monetary( "Debit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_debit_credit', searcher='search_debit_credit') end_debit = fields.Function(Monetary( "End Debit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_account', searcher='search_account') start_credit = fields.Function(Monetary( "Start Credit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_account', searcher='search_account') credit = fields.Function(Monetary( "Credit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_debit_credit', searcher='search_debit_credit') end_credit = fields.Function(Monetary( "End Credit", currency='currency', digits='currency', states={ 'invisible': ~Eval('line_count', -1), - }, - depends=['line_count']), + }), 'get_account', searcher='search_account') line_count = fields.Function( fields.Integer("Line Count"), @@ -2074,8 +2036,7 @@ class GeneralLedgerAccountContext(ModelView): ], states={ 'invisible': Eval('from_date', False) | Eval('to_date', False), - }, - depends=['fiscalyear', 'end_period', 'from_date', 'to_date']) + }) end_period = fields.Many2One('account.period', 'End Period', domain=[ ('fiscalyear', '=', Eval('fiscalyear')), @@ -2083,8 +2044,7 @@ class GeneralLedgerAccountContext(ModelView): ], states={ 'invisible': Eval('from_date', False) | Eval('to_date', False), - }, - depends=['fiscalyear', 'start_period', 'from_date', 'to_date']) + }) from_date = fields.Date("From Date", domain=[ If(Eval('to_date') & Eval('from_date'), @@ -2094,8 +2054,7 @@ class GeneralLedgerAccountContext(ModelView): states={ 'invisible': (Eval('start_period', False) | Eval('end_period', False)), - }, - depends=['to_date', 'start_period', 'end_period']) + }) to_date = fields.Date("To Date", domain=[ If(Eval('from_date') & Eval('to_date'), @@ -2105,8 +2064,7 @@ class GeneralLedgerAccountContext(ModelView): states={ 'invisible': (Eval('start_period', False) | Eval('end_period', False)), - }, - depends=['from_date', 'start_period', 'end_period']) + }) company = fields.Many2One('company.company', 'Company', required=True) posted = fields.Boolean('Posted Move', help="Only include posted moves.") journal = fields.Many2One( @@ -2114,7 +2072,7 @@ class GeneralLedgerAccountContext(ModelView): context={ 'company': Eval('company', -1), }, - depends=['company'], + depends={'company'}, help="Only include moves from the journal.") @classmethod @@ -2193,7 +2151,7 @@ class GeneralLedgerAccountParty(_GeneralLedgerAccount): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) @classmethod def __setup__(cls): @@ -2254,7 +2212,7 @@ class GeneralLedgerLine(ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['party_required', 'company']) + depends={'company'}) party_required = fields.Boolean('Party Required') account_party = fields.Function( fields.Many2One( @@ -2492,8 +2450,7 @@ class BalanceSheetComparisionContext(BalanceSheetContext): date_cmp = fields.Date('Date', states={ 'required': Eval('comparison', False), 'invisible': ~Eval('comparison', False), - }, - depends=['comparison']) + }) @classmethod def default_comparison(cls): @@ -2521,8 +2478,7 @@ class IncomeStatementContext(ModelView): required=True, domain=[ ('company', '=', Eval('company')), - ], - depends=['company']) + ]) start_period = fields.Many2One('account.period', 'Start Period', domain=[ ('fiscalyear', '=', Eval('fiscalyear')), @@ -2530,8 +2486,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': Eval('from_date', False) | Eval('to_date', False), - }, - depends=['end_period', 'fiscalyear', 'from_date', 'to_date']) + }) end_period = fields.Many2One('account.period', 'End Period', domain=[ ('fiscalyear', '=', Eval('fiscalyear')), @@ -2539,8 +2494,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': Eval('from_date', False) | Eval('to_date', False), - }, - depends=['start_period', 'fiscalyear', 'from_date', 'to_date']) + }) from_date = fields.Date("From Date", domain=[ If(Eval('to_date') & Eval('from_date'), @@ -2550,8 +2504,7 @@ class IncomeStatementContext(ModelView): states={ 'invisible': ( Eval('start_period', False) | Eval('end_period', False)), - }, - depends=['to_date', 'start_period', 'end_period']) + }) to_date = fields.Date("To Date", domain=[ If(Eval('from_date') & Eval('to_date'), @@ -2561,8 +2514,7 @@ class IncomeStatementContext(ModelView): states={ 'invisible': ( Eval('start_period', False) | Eval('end_period', False)), - }, - depends=['from_date', 'start_period', 'end_period']) + }) company = fields.Many2One('company.company', 'Company', required=True) posted = fields.Boolean('Posted Move', help="Only include posted moves.") comparison = fields.Boolean('Comparison') @@ -2573,8 +2525,7 @@ class IncomeStatementContext(ModelView): }, domain=[ ('company', '=', Eval('company')), - ], - depends=['company']) + ]) start_period_cmp = fields.Many2One('account.period', 'Start Period', domain=[ ('fiscalyear', '=', Eval('fiscalyear_cmp')), @@ -2582,8 +2533,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': ~Eval('comparison', False), - }, - depends=['end_period_cmp', 'fiscalyear_cmp']) + }) end_period_cmp = fields.Many2One('account.period', 'End Period', domain=[ ('fiscalyear', '=', Eval('fiscalyear_cmp')), @@ -2591,8 +2541,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': ~Eval('comparison', False), - }, - depends=['start_period_cmp', 'fiscalyear_cmp']) + }) from_date_cmp = fields.Date("From Date", domain=[ If(Eval('to_date_cmp') & Eval('from_date_cmp'), @@ -2601,8 +2550,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': ~Eval('comparison', False), - }, - depends=['to_date_cmp', 'comparison']) + }) to_date_cmp = fields.Date("To Date", domain=[ If(Eval('from_date_cmp') & Eval('to_date_cmp'), @@ -2611,8 +2559,7 @@ class IncomeStatementContext(ModelView): ], states={ 'invisible': ~Eval('comparison', False), - }, - depends=['from_date_cmp', 'comparison']) + }) @staticmethod def default_fiscalyear(): @@ -2684,13 +2631,11 @@ class AgedBalanceContext(ModelView): term2 = fields.Integer("Second Term", required=True, domain=[ ('term2', '>', Eval('term1', 0)), - ], - depends=['term1']) + ]) term3 = fields.Integer("Third Term", required=True, domain=[ ('term3', '>', Eval('term2', 0)), - ], - depends=['term2']) + ]) unit = fields.Selection([ ('day', 'Days'), ('week', "Weeks"), @@ -2757,7 +2702,7 @@ class AgedBalance(ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) company = fields.Many2One('company.company', 'Company') term0 = Monetary( "Now", currency='currency', digits='currency') @@ -2947,8 +2892,7 @@ class CreateChartProperties(ModelView): ('type.receivable', '=', True), ('party_required', '=', True), ('company', '=', Eval('company')), - ], - depends=['company']) + ]) account_payable = fields.Many2One('account.account', 'Default Payable Account', domain=[ @@ -2956,8 +2900,7 @@ class CreateChartProperties(ModelView): ('type.payable', '=', True), ('party_required', '=', True), ('company', '=', Eval('company')), - ], - depends=['company']) + ]) class CreateChart(Wizard): diff --git a/common.py b/common.py index 8df8c6e6a4..bde4103e70 100644 --- a/common.py +++ b/common.py @@ -19,16 +19,14 @@ class PeriodMixin(Model): If(Eval('start_date') & Eval('end_date'), ('start_date', '<=', Eval('end_date')), ()), - ], - depends=['end_date']) + ]) end_date = fields.Date( "End Date", domain=[ If(Eval('start_date') & Eval('end_date'), ('end_date', '>=', Eval('start_date')), ()), - ], - depends=['start_date']) + ]) @classmethod def __setup__(cls): @@ -51,7 +49,7 @@ class PeriodMixin(Model): ('end_date', '=', None), ], ] - cls.parent.depends.extend(['company', 'start_date', 'end_date']) + cls.parent.depends.update({'company', 'start_date', 'end_date'}) cls.childs.domain = [ ('company', '=', Eval('company', 0)), @@ -62,7 +60,7 @@ class PeriodMixin(Model): ('end_date', '<=', Eval('end_date', None)), ()), ] - cls.childs.depends.extend(['company', 'start_date', 'end_date']) + cls.childs.depends.update({'company', 'start_date', 'end_date'}) class ActivePeriodMixin(PeriodMixin): diff --git a/configuration.py b/configuration.py index 1f9f4ed3ea..52c622c9e5 100644 --- a/configuration.py +++ b/configuration.py @@ -89,16 +89,14 @@ class ConfigurationDefaultAccount(ModelSQL, CompanyValueMixin): ('type.receivable', '=', True), ('party_required', '=', True), ('company', '=', Eval('company', -1)), - ], - depends=['company']) + ]) default_account_payable = fields.Many2One( 'account.account', "Default Account Payable", domain=[ ('type.payable', '=', True), ('party_required', '=', True), ('company', '=', Eval('company', -1)), - ], - depends=['company']) + ]) class DefaultTaxRule(ModelSQL, CompanyValueMixin): @@ -109,15 +107,13 @@ class DefaultTaxRule(ModelSQL, CompanyValueMixin): domain=[ ('company', '=', Eval('company', -1)), ('kind', 'in', ['sale', 'both']), - ], - depends=['company']) + ]) default_supplier_tax_rule = fields.Many2One( 'account.tax.rule', "Default Supplier Tax Rule", domain=[ ('company', '=', Eval('company', -1)), ('kind', 'in', ['purchase', 'both']), - ], - depends=['company']) + ]) class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin): @@ -128,7 +124,7 @@ class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) tax_rounding = fields.Selection(tax_roundings, 'Method', required=True) @classmethod @@ -160,8 +156,7 @@ class Sequence(ModelSQL, CompanyValueMixin): ('company', 'in', [Eval('company', -1), None]), ('sequence_type', '=', Id('account', 'sequence_type_account_move_reconciliation')), - ], - depends=['company']) + ]) @classmethod def default_reconciliation_sequence(cls): diff --git a/fiscalyear.py b/fiscalyear.py index c6542ecb2e..fa85894549 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -20,26 +20,22 @@ from .exceptions import ( STATES = { 'readonly': Eval('state') != 'open', } -DEPENDS = ['state'] class FiscalYear(Workflow, ModelSQL, ModelView): 'Fiscal Year' __name__ = 'account.fiscalyear' - name = fields.Char('Name', size=None, required=True, depends=DEPENDS) + name = fields.Char('Name', size=None, required=True) start_date = fields.Date('Starting Date', required=True, states=STATES, - domain=[('start_date', '<=', Eval('end_date', None))], - depends=DEPENDS + ['end_date']) + domain=[('start_date', '<=', Eval('end_date', None))]) end_date = fields.Date('Ending Date', required=True, states=STATES, - domain=[('end_date', '>=', Eval('start_date', None))], - depends=DEPENDS + ['start_date']) + domain=[('end_date', '>=', Eval('start_date', None))]) periods = fields.One2Many('account.period', 'fiscalyear', 'Periods', states=STATES, domain=[ ('company', '=', Eval('company')), ], - order=[('start_date', 'ASC'), ('id', 'ASC')], - depends=DEPENDS + ['company']) + order=[('start_date', 'ASC'), ('id', 'ASC')]) state = fields.Selection([ ('open', 'Open'), ('close', 'Close'), @@ -51,8 +47,7 @@ class FiscalYear(Workflow, ModelSQL, ModelView): ('sequence_type', '=', Id('account', 'sequence_type_account_move')), ('company', '=', Eval('company')), - ], - depends=['company']) + ]) company = fields.Many2One( 'company.company', "Company", required=True, select=True) icon = fields.Function(fields.Char("Icon"), 'get_icon') @@ -353,13 +348,12 @@ class BalanceNonDeferralStart(ModelView): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) period = fields.Many2One('account.period', 'Period', required=True, domain=[ ('fiscalyear', '=', Eval('fiscalyear')), ('type', '=', 'adjustment'), - ], - depends=['fiscalyear']) + ]) credit_account = fields.Many2One('account.account', 'Credit Account', required=True, domain=[ @@ -367,8 +361,7 @@ class BalanceNonDeferralStart(ModelView): ('closed', '!=', True), ('company', '=', Eval('company', -1)), ('deferral', '=', True), - ], - depends=['company']) + ]) debit_account = fields.Many2One('account.account', 'Debit Account', required=True, domain=[ @@ -376,8 +369,7 @@ class BalanceNonDeferralStart(ModelView): ('closed', '!=', True), ('company', '=', Eval('company', -1)), ('deferral', '=', True), - ], - depends=['company']) + ]) @fields.depends('fiscalyear') def on_change_with_company(self, name=None): @@ -481,7 +473,6 @@ class CreatePeriodsStart(ModelView): states={ 'invisible': Eval('frequency') != 'other', }, - depends=['frequency'], help="The length of each period, in months.") end_day = fields.Integer("End Day", required=True, help="The day of the month on which periods end.\n" @@ -540,7 +531,6 @@ class RenewFiscalYearStart(ModelView): domain=[ ('company', '=', Eval('company')), ], - depends=['company'], help="Used as reference for fiscalyear configuration.") start_date = fields.Date("Start Date", required=True) end_date = fields.Date("End Date", required=True) diff --git a/journal.py b/journal.py index 059ae95174..1a3a582927 100644 --- a/journal.py +++ b/journal.py @@ -21,7 +21,6 @@ from trytond.transaction import Transaction STATES = { 'readonly': Eval('state') == 'close', } -DEPENDS = ['state'] class Journal( @@ -161,7 +160,7 @@ class JournalSequence(ModelSQL, CompanyValueMixin): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) sequence = fields.Many2One( 'ir.sequence', "Sequence", domain=[ @@ -169,7 +168,7 @@ class JournalSequence(ModelSQL, CompanyValueMixin): Id('account', 'sequence_type_account_journal')), ('company', 'in', [Eval('company', -1), None]), ], - depends=['company']) + depends={'company'}) @classmethod def __register__(cls, module_name): @@ -216,9 +215,9 @@ class JournalPeriod( 'Journal - Period' __name__ = 'account.journal.period' journal = fields.Many2One('account.journal', 'Journal', required=True, - ondelete='CASCADE', states=STATES, depends=DEPENDS) + ondelete='CASCADE', states=STATES) period = fields.Many2One('account.period', 'Period', required=True, - ondelete='CASCADE', states=STATES, depends=DEPENDS) + ondelete='CASCADE', states=STATES) icon = fields.Function(fields.Char('Icon'), 'get_icon') state = fields.Selection([ ('open', 'Open'), @@ -248,7 +247,6 @@ class JournalPeriod( }, }) cls.active.states = STATES - cls.active.depends = DEPENDS @classmethod def __register__(cls, module_name): diff --git a/move.py b/move.py index 441d2f7b1f..b96b474306 100644 --- a/move.py +++ b/move.py @@ -34,11 +34,9 @@ from .exceptions import ( _MOVE_STATES = { 'readonly': Eval('state') == 'posted', } -_MOVE_DEPENDS = ['state'] _LINE_STATES = { 'readonly': Eval('state') == 'valid', } -_LINE_DEPENDS = ['state'] class Move(ModelSQL, ModelView): @@ -49,7 +47,7 @@ class Move(ModelSQL, ModelView): post_number = fields.Char('Post Number', readonly=True, help='Also known as Folio Number.') company = fields.Many2One('company.company', 'Company', required=True, - states=_MOVE_STATES, depends=_MOVE_DEPENDS) + states=_MOVE_STATES) period = fields.Many2One('account.period', 'Period', required=True, domain=[ ('company', '=', Eval('company', -1)), @@ -57,7 +55,7 @@ class Move(ModelSQL, ModelView): ('state', '=', 'open'), ()), ], - states=_MOVE_STATES, depends=_MOVE_DEPENDS + ['company', 'state'], + states=_MOVE_STATES, select=True) journal = fields.Many2One('account.journal', 'Journal', required=True, states={ @@ -66,20 +64,19 @@ class Move(ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['number', 'company']) + depends={'company'}) date = fields.Date('Effective Date', required=True, select=True, - states=_MOVE_STATES, depends=_MOVE_DEPENDS) + states=_MOVE_STATES) post_date = fields.Date('Post Date', readonly=True) - description = fields.Char('Description', states=_MOVE_STATES, - depends=_MOVE_DEPENDS) + description = fields.Char('Description', states=_MOVE_STATES) origin = fields.Reference('Origin', selection='get_origin', - states=_MOVE_STATES, depends=_MOVE_DEPENDS) + states=_MOVE_STATES) state = fields.Selection([ ('draft', 'Draft'), ('posted', 'Posted'), ], 'State', required=True, readonly=True, select=True, sort=False) lines = fields.One2Many('account.move.line', 'move', 'Lines', - states=_MOVE_STATES, depends=_MOVE_DEPENDS + ['company'], + states=_MOVE_STATES, depends={'company'}, context={ 'journal': Eval('journal'), 'period': Eval('period'), @@ -485,8 +482,7 @@ class Reconciliation(ModelSQL, ModelView): 'account.move.line', 'reconciliation', 'Lines', domain=[ ('move.company', '=', Eval('company', -1)), - ], - depends=['company']) + ]) date = fields.Date('Date', required=True, select=True, help='Highest date of the reconciled lines.') delegate_to = fields.Many2One( @@ -494,7 +490,6 @@ class Reconciliation(ModelSQL, ModelView): domain=[ ('move.company', '=', Eval('company', -1)), ], - depends=['company'], help="The line to which the reconciliation status is delegated.") @classmethod @@ -723,16 +718,15 @@ class Line(MoveLineMixin, ModelSQL, ModelView): _states = { 'readonly': Eval('move_state') == 'posted', } - _depends = ['move_state'] debit = Monetary( "Debit", currency='currency', digits='currency', required=True, states=_states, - depends=['credit', 'tax_lines', 'journal'] + _depends) + depends={'credit', 'tax_lines', 'journal'}) credit = Monetary( "Credit", currency='currency', digits='currency', required=True, states=_states, - depends=['debit', 'tax_lines', 'journal'] + _depends) + depends={'debit', 'tax_lines', 'journal'}) account = fields.Many2One('account.account', 'Account', required=True, domain=[ ('company', '=', Eval('company', -1)), @@ -750,44 +744,43 @@ class Line(MoveLineMixin, ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - select=True, states=_states, depends=_depends + ['date', 'company']) + select=True, states=_states, depends={'company'}) move = fields.Many2One('account.move', 'Move', select=True, required=True, ondelete='CASCADE', states={ 'required': False, 'readonly': (((Eval('state') == 'valid') | _states['readonly']) & Bool(Eval('move'))), - }, - depends=['state'] + _depends) + }) journal = fields.Function(fields.Many2One( 'account.journal', 'Journal', states=_states, context={ 'company': Eval('company', -1), }, - depends=_depends + ['company']), + depends={'company'}), 'get_move_field', setter='set_move_field', searcher='search_move_field') period = fields.Function(fields.Many2One('account.period', 'Period', - states=_states, depends=_depends), + states=_states), 'get_move_field', setter='set_move_field', searcher='search_move_field') company = fields.Function(fields.Many2One( - 'company.company', "Company", states=_states, depends=_depends), + 'company.company', "Company", states=_states), 'get_move_field', setter='set_move_field', searcher='search_move_field') date = fields.Function(fields.Date('Effective Date', required=True, - states=_states, depends=_depends), + states=_states), 'on_change_with_date', setter='set_move_field', searcher='search_move_field') origin = fields.Reference( - "Origin", selection='get_origin', states=_states, depends=_depends) + "Origin", selection='get_origin', states=_states) move_origin = fields.Function( fields.Reference("Move Origin", selection='get_move_origin'), 'get_move_field', searcher='search_move_field') - description = fields.Char('Description', states=_states, depends=_depends) + description = fields.Char('Description', states=_states) move_description = fields.Function(fields.Char('Move Description', - states=_states, depends=_depends), + states=_states), 'get_move_field', setter='set_move_field', searcher='search_move_field') amount_second_currency = Monetary( @@ -797,7 +790,6 @@ class Line(MoveLineMixin, ModelSQL, ModelView): 'required': Bool(Eval('second_currency')), 'readonly': _states['readonly'], }, - depends=['second_currency'] + _depends, help='The amount expressed in a second currency.') second_currency = fields.Many2One('currency.currency', 'Second Currency', help='The second currency.', @@ -810,9 +802,7 @@ class Line(MoveLineMixin, ModelSQL, ModelView): 'required': (Bool(Eval('amount_second_currency')) | Bool(Eval('second_currency_required'))), 'readonly': _states['readonly'] - }, - depends=['amount_second_currency', 'second_currency_required'] - + _depends) + }) second_currency_required = fields.Function( fields.Many2One('currency.currency', "Second Currency Required"), 'on_change_with_second_currency_required') @@ -825,7 +815,7 @@ class Line(MoveLineMixin, ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['party_required', 'company'] + _depends, ondelete='RESTRICT') + depends={'company'}, ondelete='RESTRICT') party_required = fields.Function(fields.Boolean('Party Required'), 'on_change_with_party_required') maturity_date = fields.Date('Maturity Date', @@ -852,7 +842,7 @@ class Line(MoveLineMixin, ModelSQL, ModelView): amount_currency = fields.Function(fields.Many2One('currency.currency', 'Amount Currency'), 'get_amount_currency') - del _states, _depends + del _states @classmethod def __setup__(cls): @@ -1416,23 +1406,21 @@ class WriteOff(DeactivableMixin, ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) credit_account = fields.Many2One('account.account', "Credit Account", required=True, domain=[ ('type', '!=', None), ('closed', '!=', True), ('company', '=', Eval('company')), - ], - depends=['company']) + ]) debit_account = fields.Many2One('account.account', "Debit Account", required=True, domain=[ ('type', '!=', None), ('closed', '!=', True), ('company', '=', Eval('company')), - ], - depends=['company']) + ]) @classmethod def __setup__(cls): @@ -1586,8 +1574,7 @@ class ReconcileLinesWriteOff(ModelView): required=True, domain=[ ('company', '=', Eval('company')), - ], - depends=['company']) + ]) date = fields.Date('Date', required=True) amount = Monetary( "Amount", currency='currency', digits='currency', readonly=True) @@ -1890,30 +1877,28 @@ class ReconcileShow(ModelView): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) party = fields.Many2One( 'party.party', 'Party', readonly=True, context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) lines = fields.Many2Many('account.move.line', None, None, 'Lines', domain=[ ('account', '=', Eval('account')), ('party', '=', Eval('party')), ('reconciliation', '=', None), - ], - depends=['account', 'party']) + ]) _write_off_states = { 'required': Bool(Eval('write_off_amount', 0)), 'invisible': ~Eval('write_off_amount', 0), } - _write_off_depends = ['write_off_amount'] write_off_amount = fields.Function(Monetary( "Amount", currency='currency', digits='currency', - states=_write_off_states, depends=_write_off_depends), + states=_write_off_states), 'on_change_with_write_off_amount') currency = fields.Function(fields.Many2One( 'currency.currency', "Currency"), @@ -1923,13 +1908,12 @@ class ReconcileShow(ModelView): domain=[ ('company', '=', Eval('company', -1)), ], - states=_write_off_states, depends=_write_off_depends + ['company']) - date = fields.Date('Date', - states=_write_off_states, depends=_write_off_depends) + states=_write_off_states) + date = fields.Date('Date', states=_write_off_states) description = fields.Char('Description', states={ 'invisible': _write_off_states['invisible'], - }, depends=_write_off_depends) + }) @fields.depends('lines', 'currency') def on_change_with_write_off_amount(self, name=None): @@ -2427,7 +2411,6 @@ class RescheduleLinesStart(ModelView): states={ 'invisible': Eval('frequency') != 'other', }, - depends=['frequency'], help="The length of each period, in months.") amount = Monetary( "Amount", currency='currency', digits='currency', @@ -2445,8 +2428,7 @@ class RescheduleLinesStart(ModelView): ('amount', '>=', Eval('total_amount', 0)), ('amount', '<', 0), ]), - [])], - depends=['number', 'total_amount']) + [])]) number = fields.Integer( "Number", domain=[ @@ -2455,8 +2437,7 @@ class RescheduleLinesStart(ModelView): states={ 'required': ~Eval('amount'), 'invisible': Bool(Eval('amount')), - }, - depends=['amount']) + }) total_amount = fields.Numeric("Total Amount", readonly=True) currency = fields.Many2One('currency.currency', "Currency", readonly=True) @@ -2488,8 +2469,7 @@ class RescheduleLinesPreview(ModelView): 'account.move.line.reschedule.term', None, "Terms", domain=[ ('currency', '=', Eval('currency', -1)), - ], - depends=['currency']) + ]) currency = fields.Many2One('currency.currency', "Currency", readonly=True) diff --git a/move_template.py b/move_template.py index 2333400ce2..cbb3aa6951 100644 --- a/move_template.py +++ b/move_template.py @@ -30,7 +30,7 @@ class MoveTemplate(DeactivableMixin, ModelSQL, ModelView): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) date = fields.Char('Date', help='Leave empty for today.') description = fields.Char('Description', help="Keyword values substitutions are identified " @@ -38,8 +38,7 @@ class MoveTemplate(DeactivableMixin, ModelSQL, ModelView): lines = fields.One2Many('account.move.line.template', 'move', 'Lines', domain=[ ('account.company', '=', Eval('company', -1)), - ], - depends=['company']) + ]) @staticmethod def default_company(): @@ -80,7 +79,7 @@ class MoveTemplateKeyword(sequence_ordered(), ModelSQL, ModelView): digits = fields.Integer('Digits', states={ 'invisible': Eval('type_') != 'numeric', 'required': Eval('type_') == 'numeric', - }, depends=['type_']) + }) @classmethod def __setup__(cls): @@ -171,14 +170,12 @@ class MoveLineTemplate(ModelSQL, ModelView): ('type', '!=', None), ('closed', '!=', True), ('company', '=', Eval('_parent_move', {}).get('company', -1)), - ], - depends=['move']) + ]) party = fields.Char('Party', states={ 'required': Eval('party_required', False), 'invisible': ~Eval('party_required', False), }, - depends=['party_required'], help="The name of the 'Party' keyword.") party_required = fields.Function(fields.Boolean('Party Required'), 'on_change_with_party_required') @@ -261,7 +258,7 @@ class TaxLineTemplate(ModelSQL, ModelView): ('company', '=', Eval('_parent_line', {} ).get('_parent_move', {}).get('company', -1)), ], - depends=['line']) + depends={'line'}) @classmethod def __setup__(cls): diff --git a/party.py b/party.py index 1fbd02dcef..72d6cd17ef 100644 --- a/party.py +++ b/party.py @@ -297,7 +297,7 @@ class PartyAccount(ModelSQL, CompanyValueMixin): context={ 'company': Eval('company', -1), }, - depends=['company']) + depends={'company'}) account_payable = fields.Many2One( 'account.account', "Account Payable", domain=[ @@ -305,7 +305,7 @@ class PartyAccount(ModelSQL, CompanyValueMixin): ('party_required', '=', True), ('company', '=', Eval('company', -1)), ], - depends=['company'], ondelete='RESTRICT') + ondelete='RESTRICT') account_receivable = fields.Many2One( 'account.account', "Account Receivable", domain=[ @@ -313,21 +313,21 @@ class PartyAccount(ModelSQL, CompanyValueMixin): ('party_required', '=', True), ('company', '=', Eval('company', -1)), ], - depends=['company'], ondelete='RESTRICT') + ondelete='RESTRICT') customer_tax_rule = fields.Many2One( 'account.tax.rule', "Customer Tax Rule", domain=[ ('company', '=', Eval('company', -1)), ('kind', 'in', ['sale', 'both']), ], - depends=['company'], ondelete='RESTRICT') + ondelete='RESTRICT') supplier_tax_rule = fields.Many2One( 'account.tax.rule', "Supplier Tax Rule", domain=[ ('company', '=', Eval('company', -1)), ('kind', 'in', ['purchase', 'both']), ], - depends=['company'], ondelete='RESTRICT') + ondelete='RESTRICT') @classmethod def __register__(cls, module_name): diff --git a/period.py b/period.py index c423068097..6922ae22b3 100644 --- a/period.py +++ b/period.py @@ -16,7 +16,6 @@ from .exceptions import ( _STATES = { 'readonly': Eval('state') != 'open', } -_DEPENDS = ['state'] class Period(Workflow, ModelSQL, ModelView): @@ -25,12 +24,12 @@ class Period(Workflow, ModelSQL, ModelView): name = fields.Char('Name', required=True) start_date = fields.Date('Starting Date', required=True, states=_STATES, domain=[('start_date', '<=', Eval('end_date', None))], - depends=_DEPENDS + ['end_date'], select=True) + select=True) end_date = fields.Date('Ending Date', required=True, states=_STATES, domain=[('end_date', '>=', Eval('start_date', None))], - depends=_DEPENDS + ['start_date'], select=True) + select=True) fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year', - required=True, states=_STATES, depends=_DEPENDS, select=True) + required=True, states=_STATES, select=True) state = fields.Selection([ ('open', 'Open'), ('close', 'Close'), @@ -44,13 +43,12 @@ class Period(Workflow, ModelSQL, ModelView): ('company', '=', None), ('company', '=', Eval('company', -1)), ], - ], - depends=['company']) + ]) type = fields.Selection([ ('standard', 'Standard'), ('adjustment', 'Adjustment'), ], 'Type', required=True, - states=_STATES, depends=_DEPENDS, select=True) + states=_STATES, select=True) company = fields.Function(fields.Many2One('company.company', 'Company',), 'on_change_with_company', searcher='search_company') icon = fields.Function(fields.Char("Icon"), 'get_icon') diff --git a/tax.py b/tax.py index ceb4b11278..89aa243c4e 100644 --- a/tax.py +++ b/tax.py @@ -146,8 +146,7 @@ class TaxCode(ActivePeriodMixin, tree(), ModelSQL, ModelView): help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) description = fields.Text('Description') del _states @@ -370,7 +369,7 @@ class TaxCodeLine(ModelSQL, ModelView): domain=[ ('company', '=', Eval('_parent_code', {}).get('company')), ], - depends=['code']) + depends={'code'}) amount = fields.Selection([ ('tax', "Tax"), ('base', "Base"), @@ -386,8 +385,7 @@ class TaxCodeLine(ModelSQL, ModelView): help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) del _states @@ -476,15 +474,13 @@ class OpenChartTaxCodeStart(ModelView): states={ 'invisible': Eval('method') != 'fiscalyear', 'required': Eval('method') == 'fiscalyear', - }, - depends=['method']) + }) periods = fields.Many2Many('account.period', None, None, 'Periods', help='Leave empty for all periods of all open fiscal year.', states={ 'invisible': Eval('method') != 'periods', 'required': Eval('method') == 'periods', - }, - depends=['method']) + }) @staticmethod def default_method(): @@ -530,21 +526,19 @@ class TaxTemplate(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): 'account.tax.group', 'Group', states={ 'invisible': Bool(Eval('parent')), - }, - depends=['parent']) + }) start_date = fields.Date('Starting Date') end_date = fields.Date('Ending Date') amount = fields.Numeric('Amount', digits=(16, 8), states={ 'required': Eval('type') == 'fixed', 'invisible': Eval('type') != 'fixed', - }, - depends=['type']) + }) rate = fields.Numeric('Rate', digits=(14, 10), states={ 'required': Eval('type') == 'percentage', 'invisible': Eval('type') != 'percentage', - }, depends=['type']) + }) type = fields.Selection([ ('percentage', 'Percentage'), ('fixed', 'Fixed'), @@ -553,8 +547,7 @@ class TaxTemplate(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): update_unit_price = fields.Boolean('Update Unit Price', states={ 'invisible': Bool(Eval('parent')), - }, - depends=['parent']) + }) parent = fields.Many2One('account.tax.template', 'Parent') childs = fields.One2Many('account.tax.template', 'parent', 'Children') invoice_account = fields.Many2One( @@ -565,8 +558,7 @@ class TaxTemplate(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): ], states={ 'required': Eval('type') != 'none', - }, - depends=['type']) + }) credit_note_account = fields.Many2One( 'account.account.template', 'Credit Note Account', domain=[ @@ -575,8 +567,7 @@ class TaxTemplate(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): ], states={ 'required': Eval('type') != 'none', - }, - depends=['type']) + }) account = fields.Many2One('account.account.template', 'Account Template', domain=[('parent', '=', None)], required=True) legal_notice = fields.Text("Legal Notice") @@ -704,7 +695,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): states={ 'invisible': Bool(Eval('parent')), 'readonly': _states['readonly'], - }, depends=['parent']) + }) start_date = fields.Date('Starting Date', states=_states) end_date = fields.Date('Ending Date', states=_states) amount = fields.Numeric('Amount', digits=(16, 8), @@ -712,14 +703,13 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): 'required': Eval('type') == 'fixed', 'invisible': Eval('type') != 'fixed', 'readonly': _states['readonly'], - }, help='In company\'s currency.', - depends=['type']) + }, help='In company\'s currency.') rate = fields.Numeric('Rate', digits=(14, 10), states={ 'required': Eval('type') == 'percentage', 'invisible': Eval('type') != 'percentage', 'readonly': _states['readonly'], - }, depends=['type']) + }) type = fields.Selection([ ('percentage', 'Percentage'), ('fixed', 'Fixed'), @@ -730,7 +720,6 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): 'invisible': Bool(Eval('parent')), 'readonly': _states['readonly'], }, - depends=['parent'], help=('If checked then the unit price for further tax computation will' ' be modified by this tax.')) parent = fields.Many2One('account.tax', 'Parent', ondelete='CASCADE', @@ -747,8 +736,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): states={ 'readonly': _states['readonly'], 'required': Eval('type') != 'none', - }, - depends=['company', 'type']) + }) credit_note_account = fields.Many2One('account.account', 'Credit Note Account', domain=[ @@ -759,8 +747,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): states={ 'readonly': _states['readonly'], 'required': Eval('type') != 'none', - }, - depends=['company', 'type']) + }) legal_notice = fields.Text("Legal Notice", translate=True, states=_states) template = fields.Many2One('account.tax.template', 'Template', @@ -769,8 +756,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) invoice_base_amount = fields.Function(Monetary( "Invoice Base Amount", currency='currency', digits='currency'), @@ -1236,8 +1222,7 @@ class TaxLine(ModelSQL, ModelView): ondelete='RESTRICT', required=True, domain=[ ('company', '=', Eval('company', -1)), - ], - depends=['company']) + ]) move_line = fields.Many2One('account.move.line', 'Move Line', required=True, select=True, ondelete='CASCADE') company = fields.Function(fields.Many2One('company.company', 'Company'), @@ -1415,8 +1400,7 @@ class TaxRule(ModelSQL, ModelView): help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) del _states @staticmethod @@ -1506,7 +1490,7 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView): ], help=('If the original tax template is filled, the rule will be ' 'applied only for this tax template.'), - depends=['group', 'rule'], + depends={'rule'}, ondelete='RESTRICT') keep_origin = fields.Boolean("Keep Origin", help="Check to append the original tax to substituted tax.") @@ -1525,7 +1509,7 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView): ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], ], - depends=['group', 'rule'], + depends={'rule'}, ondelete='RESTRICT') @classmethod @@ -1627,7 +1611,7 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): ], help=('If the original tax is filled, the rule will be applied ' 'only for this tax.'), - depends=['group', 'rule'], + depends={'rule'}, ondelete='RESTRICT', states=_states) keep_origin = fields.Boolean("Keep Origin", states=_states, help="Check to append the original tax to substituted tax.") @@ -1646,7 +1630,7 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): ('group.kind', 'in', ['sale', 'purchase', 'both']))), ], ], - depends=['group', 'rule'], + depends={'rule'}, ondelete='RESTRICT', states=_states) template = fields.Many2One( 'account.tax.rule.line.template', 'Template', ondelete='CASCADE') @@ -1654,8 +1638,7 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin): help="Check to override template definition", states={ 'invisible': ~Bool(Eval('template', -1)), - }, - depends=['template']) + }) del _states @classmethod