From 3128e8424373c545ea821c6d7e067f431f5b54d3 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 4 Apr 2017 13:46:19 +0200 Subject: [PATCH] [FIX] account: aged receivable - Create an invoice of 10000 at date 2016-11-30, due 2017-02-28 - Make a partial payment of 1500 at date 2016-11-09 - Make a partial payment of 1000 at date 2016-11-30 - Make a partial payment of 2000 at date 2017-01-30 At current date (e.g. 2017-04-04), run the Aged Partner Balance. 5500 is still due, but set to the +120 days period instead of 30-60. opw-725890 --- .../report/account_aged_partner_balance.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py index b7bc1c32586..cb77e0f578c 100644 --- a/addons/account/report/account_aged_partner_balance.py +++ b/addons/account/report/account_aged_partner_balance.py @@ -178,9 +178,20 @@ class aged_trial_report(report_sxw.rml_parse, common_report_header): partners_amount = dict((i[0],0) for i in partners_partial) for partner_info in partners_partial: if partner_info[2]: - # in case of partial reconciliation, we want to keep the left amount in the oldest period - self.cr.execute('''SELECT MIN(COALESCE(date_maturity,date)) FROM account_move_line WHERE reconcile_partial_id = %s''', (partner_info[2],)) + # in case of partial reconciliation, we want to keep the remaining amount in the + # period corresponding to the maturity date of the invoice. + self.cr.execute(''' + SELECT MAX(COALESCE(l.date_maturity, l.date)) + FROM account_move_line AS l + JOIN account_account AS a ON l.account_id = a.id + WHERE reconcile_partial_id = %s + AND a.type IN %s + ''', (partner_info[2], tuple(self.ACCOUNT_TYPE),)) date = self.cr.fetchall() + # Just in case date is not defined (but it should be defined) + if date and not date[0][0]: + self.cr.execute('''SELECT MIN(COALESCE(date_maturity,date)) FROM account_move_line WHERE reconcile_partial_id = %s''', (partner_info[2],)) + date = self.cr.fetchall() partial = False if 'BETWEEN' in dates_query: partial = date and args_list[-3] <= date[0][0] <= args_list[-2]