From 095ac6509b321e334d7e5bd95fe769b8be3ac893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 27 May 2025 20:00:18 +0200 Subject: [PATCH] Use first description of statement lines as description of move line without origin Closes #14038 --- modules/account_statement/account.py | 36 ++++++++++++++++++- .../tests/scenario_account_statement.rst | 4 +-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/modules/account_statement/account.py b/modules/account_statement/account.py index 8d60e5acf2..4193374da3 100644 --- a/modules/account_statement/account.py +++ b/modules/account_statement/account.py @@ -1,7 +1,7 @@ # 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.i18n import gettext -from trytond.model import ModelView, dualmethod +from trytond.model import ModelView, dualmethod, fields from trytond.modules.account.exceptions import PostError from trytond.pool import Pool, PoolMeta @@ -18,6 +18,9 @@ class Journal(metaclass=PoolMeta): class Move(metaclass=PoolMeta): __name__ = 'account.move' + statement_lines = fields.One2Many( + 'account.statement.line', 'move', "Statement Lines", readonly=True) + @classmethod def _get_origin(cls): return super()._get_origin() + ['account.statement'] @@ -36,6 +39,12 @@ class Move(metaclass=PoolMeta): statement=move.origin.rec_name)) super().post(moves) + @classmethod + def copy(cls, moves, default=None): + default = default.copy() if default is not None else {} + default.setdefault('statement_lines') + return super().copy(moves, default=default) + class MoveLine(metaclass=PoolMeta): __name__ = 'account.move.line' @@ -43,3 +52,28 @@ class MoveLine(metaclass=PoolMeta): @classmethod def _get_origin(cls): return super()._get_origin() + ['account.statement.line'] + + @fields.depends('move', '_parent_move.statement_lines') + def on_change_with_description_used(self, name=None): + description = super().on_change_with_description_used(name=name) + if (not description + and self.move + and getattr(self.move, 'statement_lines', None)): + for statement_line in self.move.statement_lines: + if statement_line.description: + description = statement_line.description + break + return description + + @classmethod + def search_description_used(cls, name, clause): + operator = clause[1] + if operator.startswith('!') or operator.startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + domain = [bool_op, + super().search_description_used(name, clause), + ('move.statement_lines.description', *clause[1:]), + ] + return domain diff --git a/modules/account_statement/tests/scenario_account_statement.rst b/modules/account_statement/tests/scenario_account_statement.rst index 4899282aca..0a3f0c1ad9 100644 --- a/modules/account_statement/tests/scenario_account_statement.rst +++ b/modules/account_statement/tests/scenario_account_statement.rst @@ -250,12 +250,12 @@ Test posted moves:: >>> statement_line = statement.lines[0] >>> move = statement_line.move >>> sorted((l.description_used or '' for l in move.lines)) - ['', 'description', 'other description'] + ['description', 'description', 'other description'] >>> statement_line = statement.lines[2] >>> move = statement_line.move >>> sorted((l.description_used or '' for l in move.lines)) - ['', 'description'] + ['description', 'description'] Test invoice state::