From 436eb6945063a05e6899559dab239bb5f912be37 Mon Sep 17 00:00:00 2001 From: Cas Vissers Date: Tue, 2 Apr 2019 10:20:24 +0000 Subject: [PATCH] [FIX] account: reconcile older invoices first Often an invoice with the same amount is send to the same customer every week/month. If the customer pays just the amount, without any matching invoice information, common practice is to take the oldest invoice first. Odoo currently suggests the invoice with the highest due date. After the fix Odoo will suggest the invoice with the lowest due date. closes odoo/odoo#32334 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/account_bank_statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 9e9228947ce..51aafbd2b78 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -658,7 +658,7 @@ class AccountBankStatementLine(models.Model): liquidity_amt_clause = currency and '%(amount)s::numeric' or 'abs(%(amount)s::numeric)' sql_query = self._get_common_sql_query(excluded_ids=excluded_ids) + \ " AND ("+field+" = %(amount)s::numeric OR (acc.internal_type = 'liquidity' AND "+liquidity_field+" = " + liquidity_amt_clause + ")) \ - ORDER BY date_maturity desc, aml.id desc LIMIT 1" + ORDER BY date_maturity asc, aml.id desc LIMIT 1" self.env.cr.execute(sql_query, params) results = self.env.cr.fetchone() if results: