From b0fa1dd28e19cf21bba77fb95ebd824533a393b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 18 Jan 2025 12:57:41 +0100 Subject: [PATCH] Sort SEPA payments by date In order to compute the proper sequence type, the payments must be ordered by ascending date in case there are many payments for a first used mandate. Closes #12614 --- modules/account_payment_sepa/payment.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/account_payment_sepa/payment.py b/modules/account_payment_sepa/payment.py index 96ce2c9a62..8b750892c4 100644 --- a/modules/account_payment_sepa/payment.py +++ b/modules/account_payment_sepa/payment.py @@ -6,6 +6,7 @@ import unicodedata import uuid from io import BytesIO from itertools import groupby +from operator import attrgetter import genshi import genshi.template @@ -218,7 +219,7 @@ class Group(metaclass=PoolMeta): Mandate = pool.get('account.payment.sepa.mandate') assert self.process_method == 'sepa' if self.kind == 'receivable': - payments = list(self.payments) + payments = sorted(self.payments, key=attrgetter('date', 'id')) mandates = Payment.get_sepa_mandates(payments) Mandate.lock(list(filter(None, mandates))) sequence_types = {}