From a96cb0a84f68f00764495ec47b29d27d4c8918e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 7 Jul 2026 19:06:14 +0200 Subject: [PATCH] Replace open journal wizard by a context model Closes #14937 --- modules/account/CHANGELOG | 1 + modules/account/doc/design/move.inc.rst | 9 + modules/account/doc/usage/create.inc.rst | 4 +- modules/account/journal.xml | 39 +--- modules/account/move.py | 173 ++++++------------ modules/account/move.xml | 54 ++++-- modules/account/tryton.cfg | 3 +- ...sk_form.xml => move_line_context_form.xml} | 3 +- .../account/view/move_line_list_editable.xml | 24 +++ modules/account/view/move_line_tree.xml | 4 +- modules/account/view/move_line_tree_move.xml | 1 + 11 files changed, 137 insertions(+), 178 deletions(-) rename modules/account/view/{open_journal_ask_form.xml => move_line_context_form.xml} (93%) create mode 100644 modules/account/view/move_line_list_editable.xml diff --git a/modules/account/CHANGELOG b/modules/account/CHANGELOG index 22db6b6e05..3112968a18 100644 --- a/modules/account/CHANGELOG +++ b/modules/account/CHANGELOG @@ -1,3 +1,4 @@ +* Replace open journal wizard by a context model * Use also maturity date to calculate reconciliation date Version 8.0.0 - 2026-04-20 diff --git a/modules/account/doc/design/move.inc.rst b/modules/account/doc/design/move.inc.rst index cf520568ff..29e9236364 100644 --- a/modules/account/doc/design/move.inc.rst +++ b/modules/account/doc/design/move.inc.rst @@ -83,6 +83,15 @@ These facts help ensure the integrity of the `Company's ` accounts and the accounting reports generated by Tryton. +.. seealso:: + + Account move lines can be found by opening the main menu item: + + |Financial --> Entries --> Lines|__ + + .. |Financial --> Entries --> Lines| replace:: :menuselection:`Financial --> Entries --> Lines` + __ https://demo.tryton.org/model/account.move.line + Wizards ------- diff --git a/modules/account/doc/usage/create.inc.rst b/modules/account/doc/usage/create.inc.rst index 1a6a1ebda7..fe9749b35e 100644 --- a/modules/account/doc/usage/create.inc.rst +++ b/modules/account/doc/usage/create.inc.rst @@ -36,8 +36,8 @@ One-off entries For entries that are only needed once, for example to set an account's initial opening balance, you can manually create an *Account Move*. -The [:menuselection:`Financial --> Entries --> Open Journal`] main menu item -provides another way of entering the details of an account move. +The [:menuselection:`Financial --> Entries --> Lines`] main menu item provides +another way of entering the details of an account move. It provides a list of individual `Account Move Lines `, which can be added to as required. diff --git a/modules/account/journal.xml b/modules/account/journal.xml index 9a2b4d601e..9e6cb87be3 100644 --- a/modules/account/journal.xml +++ b/modules/account/journal.xml @@ -112,45 +112,8 @@ this repository contains the full copyright notices and license terms. --> journal_period_list_close - - Journals - Periods - account.journal.period - - - - - - - - - - - - Journals - Periods - account.journal.period - - - - - - - - - - - - Close Journals - Periods + Journals - Periods account.journal.period diff --git a/modules/account/move.py b/modules/account/move.py index c9fe22d0df..047092d989 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -1123,35 +1123,43 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): where=table.reconciliation == Null), }) + @classmethod + def _last_move_line(cls): + "Last move line created by the current user" + transaction = Transaction() + context = transaction.context + domain = [ + ('company', '=', context.get('company')), + ('create_uid', '=', transaction.user), + ('state', '=', 'draft'), + ] + if context.get('journal') is not None: + domain.append(('move.journal', '=', context['journal'])) + if context.get('period') is not None: + domain.append(('move.period', '=', context['period'])) + lines = cls.search(domain, order=[('id', 'DESC')], limit=1) + if lines: + line, = lines + return line + @classmethod def default_date(cls): - ''' - Return the date of the last line for journal, period - or the starting date of the period - or today - ''' pool = Pool() Period = pool.get('account.period') Date = pool.get('ir.date') context = Transaction().context date = Date.today() - lines = cls.search([ - ('company', '=', context.get('company')), - ('journal', '=', context.get('journal')), - ('period', '=', context.get('period')), - ], - order=[('date', 'DESC')], limit=1) - if lines: - line, = lines + if (context.get('default_last_move_line') + and (line := cls._last_move_line())): date = line.date - elif context.get('period'): + elif context.get('period') is not None: period = Period(context['period']) if period.start_date >= date: date = period.start_date else: date = period.end_date - if context.get('date'): + elif context.get('date'): date = context['date'] return date @@ -1159,21 +1167,15 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): def default_move(cls): transaction = Transaction() context = transaction.context - if context.get('journal') and context.get('period'): - lines = cls.search([ - ('company', '=', context.get('company')), - ('move.journal', '=', context['journal']), - ('move.period', '=', context['period']), - ('create_uid', '=', transaction.user), - ('state', '=', 'draft'), - ], order=[('id', 'DESC')], limit=1) - if lines: - line, = lines - return line.move.id + if context.get('default_last_move_line'): + if line := cls._last_move_line(): + return line.move @fields.depends( 'move', 'debit', 'credit', - '_parent_move.lines', '_parent_move.company') + 'company', 'period', 'journal', + '_parent_move.lines', + '_parent_move.company', '_parent_move.period', '_parent_move.journal') def on_change_move(self): if self.move: if not self.debit and not self.credit: @@ -1182,11 +1184,21 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): self.debit = -total if total < 0 else Decimal(0) self.credit = total if total > 0 else Decimal(0) self.company = self.move.company + self.period = self.move.period + self.journal = self.move.journal @classmethod def default_company(cls): return Transaction().context.get('company') + @classmethod + def default_journal(cls): + return Transaction().context.get('journal') + + @classmethod + def default_period(cls): + return Transaction().context.get('period') + @staticmethod def default_state(): return 'draft' @@ -1502,6 +1514,10 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): attributes.append( ('/tree', 'visual', If(Bool(Eval('reconciliation')), 'muted', ''))) + else: + attributes.append( + ('/tree', 'visual', + If(Eval('state') != 'valid', 'muted', ''))) return attributes @classmethod @@ -1565,13 +1581,10 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): # Add a wizard entry for each templates context = Transaction().context - company = context.get('company') - journal = context.get('journal') - period = context.get('period') - if company and journal and period: + if context.get('default_last_move_line'): templates = Template.search([ - ('company', '=', company), - ('journal', '=', journal), + ('company', '=', context.get('company')), + ('journal', '=', context.get('journal')), ]) toolbar = dict(toolbar) action = list(toolbar['action']) @@ -1959,15 +1972,16 @@ class WriteOff(DeactivableMixin, ModelSQL, ModelView): return Transaction().context.get('company') -class OpenJournalAsk(ModelView): - __name__ = 'account.move.open_journal.ask' +class LineContext(ModelView): + __name__ = 'account.move.line.context' company = fields.Many2One('company.company', "Company", required=True) journal = fields.Many2One( - 'account.journal', 'Journal', required=True, + 'account.journal', "Journal", context={ 'company': Eval('company', None), }) - period = fields.Many2One('account.period', 'Period', required=True, + period = fields.Many2One( + 'account.period', "Period", domain=[ ('company', '=', Eval('company', -1)), ('state', '!=', 'closed'), @@ -1977,88 +1991,21 @@ class OpenJournalAsk(ModelView): def default_company(cls): return Transaction().context.get('company') + @classmethod + def default_journal(cls): + return Transaction().context.get('journal') + @classmethod def default_period(cls): pool = Pool() Period = pool.get('account.period') - if company := cls.default_company(): + if period := Transaction().context.get('period'): + return period + elif company := cls.default_company(): try: - period = Period.find(company) + return Period.find(company) except PeriodNotFoundError: - return None - return period.id - - -class OpenJournal(Wizard): - __name__ = 'account.move.open_journal' - _readonly = True - start = StateTransition() - ask = StateView('account.move.open_journal.ask', - 'account.open_journal_ask_view_form', [ - Button('Cancel', 'end', 'tryton-cancel'), - Button('Open', 'open_', 'tryton-ok', default=True), - ]) - open_ = StateAction('account.act_move_line_form') - - def transition_start(self): - if (self.model - and self.model.__name__ == 'account.journal.period' - and self.record): - return 'open_' - return 'ask' - - def default_ask(self, fields): - if (self.model - and self.model.__name__ == 'account.journal.period' - and self.record): - return { - 'company': self.record.company.id, - 'journal': self.record.journal.id, - 'period': self.record.period.id, - } - return {} - - def do_open_(self, action): - JournalPeriod = Pool().get('account.journal.period') - - if (self.model - and self.model.__name__ == 'account.journal.period' - and self.record): - journal = self.record.journal - period = self.record.period - else: - journal = self.ask.journal - period = self.ask.period - journal_periods = JournalPeriod.search([ - ('journal', '=', journal.id), - ('period', '=', period.id), - ], limit=1) - if not journal_periods: - with Transaction().new_transaction(): - journal_period, = JournalPeriod.create([{ - 'journal': journal.id, - 'period': period.id, - }]) - name = journal_period.rec_name - else: - journal_period, = journal_periods - name = journal_period.rec_name - - action['name'] += ' (%s)' % name - action['pyson_domain'] = PYSONEncoder().encode([ - ('journal', '=', journal.id), - ('period', '=', period.id), - ('company', '=', period.company.id), - ]) - action['pyson_context'] = PYSONEncoder().encode({ - 'journal': journal.id, - 'period': period.id, - 'company': period.company.id, - }) - return action, {} - - def transition_open_(self): - return 'end' + pass class OpenAccount(Wizard): diff --git a/modules/account/move.xml b/modules/account/move.xml index b9945f8bdf..f1e591756e 100644 --- a/modules/account/move.xml +++ b/modules/account/move.xml @@ -191,6 +191,13 @@ this repository contains the full copyright notices and license terms. --> move_line_tree + + account.move.line + tree + + move_line_list_editable + + account.move.line tree @@ -230,6 +237,31 @@ this repository contains the full copyright notices and license terms. --> + + + Lines + account.move.line + account.move.line.context + + + + + + + + + + + + + + + + Open Move Account account.move.open_account @@ -282,28 +314,12 @@ this repository contains the full copyright notices and license terms. --> move_line_receivable_payable_context_form - - account.move.open_journal.ask + + account.move.line.context form - open_journal_ask_form + move_line_context_form - - Open Journal - account.move.open_journal - - - tree_open - account.journal.period,-1 - - - - account.move.reconcile_lines.writeoff form diff --git a/modules/account/tryton.cfg b/modules/account/tryton.cfg index 74a4ae14cf..ad00e119e1 100644 --- a/modules/account/tryton.cfg +++ b/modules/account/tryton.cfg @@ -69,7 +69,7 @@ model: move.Line move.LineReceivablePayableContext move.WriteOff - move.OpenJournalAsk + move.LineContext move.ReconcileLinesWriteOff move.ReconcileStart move.ReconcileShow @@ -110,7 +110,6 @@ wizard: account.CreateChart account.UpdateChart account.OpenGeneralLedgerAccountParty - move.OpenJournal move.OpenAccount move.ReconcileLines move.UnreconcileLines diff --git a/modules/account/view/open_journal_ask_form.xml b/modules/account/view/move_line_context_form.xml similarity index 93% rename from modules/account/view/open_journal_ask_form.xml rename to modules/account/view/move_line_context_form.xml index 8e5df958a6..6a2b4e309c 100644 --- a/modules/account/view/open_journal_ask_form.xml +++ b/modules/account/view/move_line_context_form.xml @@ -1,12 +1,11 @@ -
+