details:   https://code.tryton.org/tryton/commit/9b3a8fcbe0f6
branch:    default
user:      Cédric Krier <[email protected]>
date:      Sat Feb 28 15:26:23 2026 +0100
description:
        Sort statement lines per origin before creating moves

        Closes #13941
diffstat:

 modules/account_statement/statement.py |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (22 lines):

diff -r ddcea8785ccd -r 9b3a8fcbe0f6 modules/account_statement/statement.py
--- a/modules/account_statement/statement.py    Mon Mar 16 10:22:14 2026 +0100
+++ b/modules/account_statement/statement.py    Sat Feb 28 15:26:23 2026 +0100
@@ -490,8 +490,16 @@
 
         moves = []
         for statement in statements:
-            for key, lines in groupby(
-                    statement.lines, key=statement._group_key):
+            if statement.origins:
+                origin_index = {
+                    o: index for index, o in enumerate(statement.origins)}
+                size = len(statement.origins)
+                sorted_lines = sorted(
+                    statement.lines,
+                    key=lambda l: origin_index.get(l.origin, size))
+            else:
+                sorted_lines = statement.lines
+            for key, lines in groupby(sorted_lines, key=statement._group_key):
                 lines = list(lines)
                 key = dict(key)
                 move = statement._get_move(key)

Reply via email to