[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
This commit is contained in:
Nicolas Martinelli 2017-04-04 13:46:19 +02:00
parent 33076f7394
commit 3128e84243
1 changed files with 13 additions and 2 deletions

View File

@ -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]