From ecaf2bc39197a5127afc6a323fb00d3b50df31ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Nov 2024 10:32:24 +0100 Subject: [PATCH] Setup explicitly the accounts, parties and currencies of reconciliation wizard It is better to not rely on missing the field on the state view but to have an explicit transition to setup the values. --- modules/account/move.py | 20 ++++++++++--------- .../tests/scenario_account_reconcile.rst | 4 ++-- .../scenario_account_reconcile_automatic.rst | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/account/move.py b/modules/account/move.py index ca8cf76637..a0e36eda7c 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -2207,8 +2207,9 @@ class Reconcile(Wizard): 'account.reconcile.start', 'account.reconcile_start_view_form', [ Button("Cancel", 'end', 'tryton-cancel'), - Button("Reconcile", 'next_', 'tryton-ok', default=True), + Button("Reconcile", 'setup', 'tryton-ok', default=True), ]) + setup = StateTransition() next_ = StateTransition() show = StateView('account.reconcile.show', 'account.reconcile_show_view_form', [ @@ -2324,8 +2325,11 @@ class Reconcile(Wizard): having=having)) return [p for p, in cursor] + def transition_setup(self): + return self.transition_next_(first=True) + @check_access - def transition_next_(self): + def transition_next_(self, first=False): pool = Pool() Line = pool.get('account.move.line') @@ -2359,20 +2363,18 @@ class Reconcile(Wizard): self.show.currencies = currencies return currency - if getattr(self.show, 'accounts', None) is None: + if first: self.show.accounts = self.get_accounts() account = next_account() if not account or (not next_party() and account.party_required): return 'end' - if self.show.account.party_required: - if getattr(self.show, 'parties', None) is None: + if self.show.account.party_required: self.show.parties = self.get_parties(self.show.account) if not next_party(): return 'end' - else: - self.show.parties = [] - self.show.party = None - if getattr(self.show, 'currencies', None) is None: + else: + self.show.parties = [] + self.show.party = None self.show.currencies = self.get_currencies( self.show.account, self.show.party) diff --git a/modules/account/tests/scenario_account_reconcile.rst b/modules/account/tests/scenario_account_reconcile.rst index 38b6544fee..76f4ebd915 100644 --- a/modules/account/tests/scenario_account_reconcile.rst +++ b/modules/account/tests/scenario_account_reconcile.rst @@ -102,14 +102,14 @@ Run Reconcile for only balanced:: >>> reconcile = Wizard('account.reconcile') >>> reconcile.form.only_balanced = True - >>> reconcile.execute('next_') + >>> reconcile.execute('setup') >>> reconcile.state 'end' Run Reconcile wizard:: >>> reconcile = Wizard('account.reconcile') - >>> reconcile.execute('next_') + >>> reconcile.execute('setup') >>> assertEqual(reconcile.form.party, (customer if party_required else None)) >>> reconcile.form.write_off_amount Decimal('0.00') diff --git a/modules/account/tests/scenario_account_reconcile_automatic.rst b/modules/account/tests/scenario_account_reconcile_automatic.rst index d25730d2c2..ef956ce843 100644 --- a/modules/account/tests/scenario_account_reconcile_automatic.rst +++ b/modules/account/tests/scenario_account_reconcile_automatic.rst @@ -75,7 +75,7 @@ Run Reconcile wizard:: >>> reconcile = Wizard('account.reconcile') >>> reconcile.form.automatic = True - >>> reconcile.execute('next_') + >>> reconcile.execute('setup') >>> lines = Line.find([('account', '=', accounts['receivable'].id)]) >>> len(lines)