From e798828de9894b82e88509fcd0820b4ca22fa9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 17 Apr 2018 17:56:02 +0200 Subject: [PATCH] Ensure None are before 0 The next index must point to the next value and not a None value which are skipped. issue7350 review38161002 --- account.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/account.py b/account.py index 4a0fba2371..d713525e10 100644 --- a/account.py +++ b/account.py @@ -2011,7 +2011,10 @@ class AgedBalance(ModelSQL, ModelView): terms = cls.get_terms() factor = cls.get_unit_factor() - term_values = sorted(terms.values(), key=lambda x: x or 0) + # Ensure None are before 0 to get the next index pointing to the next + # value and not a None value + term_values = sorted( + terms.values(), key=lambda x: ((x is not None), x or 0)) for name, value in terms.iteritems(): if value is None or factor is None or date is None: @@ -2021,7 +2024,7 @@ class AgedBalance(ModelSQL, ModelView): idx = term_values.index(value) if idx + 1 < len(terms): cond &= line.maturity_date > ( - date - term_values[idx + 1] * factor) + date - (term_values[idx + 1] or 0) * factor) else: cond |= line.maturity_date == Null columns.append(