From dda9e7b2490b1befa390d893abfe3c2e004b424f Mon Sep 17 00:00:00 2001 From: Camille Spiritus Date: Wed, 26 Oct 2022 06:48:04 +0000 Subject: [PATCH] [FIX] account: fix payment term installments ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The payment terms printed on the invoice are ordered by date. However, the order was applied on the string version of the date, which caused issues. Fixed this by formatting the date to string after the ordering. closes odoo/odoo#104388 X-original-commit: c6bc6284c390659d40a329c3b7b000579ed7c23b Signed-off-by: William André (wan) Signed-off-by: Camille Spiritus (casp) --- addons/account/models/account_move.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 1dff5c389c8..2096017c843 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1235,14 +1235,14 @@ class AccountMove(models.Model): if invoice.show_payment_term_details: sign = 1 if invoice.is_inbound(include_receipts=True) else -1 payment_term_details = [] - for line in invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term'): + for line in invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').sorted('date_maturity'): payment_term_details.append({ 'date': format_date(self.env, line.date_maturity), 'amount': sign * line.amount_currency, 'discount_date': format_date(self.env, line.discount_date), 'discount_amount_currency': sign * line.discount_amount_currency, }) - invoice.payment_term_details = sorted(payment_term_details, key=lambda t: t.get('date')) + invoice.payment_term_details = payment_term_details @api.depends('move_type', 'payment_state', 'invoice_payment_term_id') def _compute_show_payment_term_details(self):