Skip to content

Commit

Permalink
[FIX] account: aged partner report
Browse files Browse the repository at this point in the history
Let's consider an aged partner balance with a period of 30 days as of
2019-02-08. The specific dates used in the report are:

``` python
bisou = datetime.strptime('2019-02-08', "%Y-%m-%d").date()
for x in [0, 1, 30, 31, 60, 61, 90, 91, 120, 121]:
    print(x, bisou + relativedelta(days=-x))

0   2019-02-08
1   2019-02-07
30  2019-01-09
31  2019-01-08
60  2018-12-10
61  2018-12-09
90  2018-11-10
91  2018-11-09
120 2018-10-11
121 2018-10-10
```

However, the current periods generated are incorrect:

```
{'name': '0-30', 'stop': '2019-02-08', 'start': '2019-01-09'}
{'name': '30-60', 'stop': '2019-01-08', 'start': '2018-12-09'}
{'name': '60-90', 'stop': '2018-12-08', 'start': '2018-11-08'}
{'name': '90-120', 'stop': '2018-11-07', 'start': '2018-10-08'}
{'name': '+120', 'stop': '2018-10-07', 'start': False}
```

There is a clear inconsistency between the name of the period and the
date used. Moreover, the name is misleading: 0-30 includes the -0 date,
while 30-60 doesn't include the -30 date.

After the fix, the name and the periods are consistent. We also change
the first period to 1-30 since including 0 would mean to include amounts
which are not due yet.

```
{'name': '1-30', 'stop': '2019-02-07', 'start': '2019-01-09'}
{'name': '31-60', 'stop': '2019-01-08', 'start': '2018-12-10'}
{'name': '61-90', 'stop': '2018-12-09', 'start': '2018-11-10'}
{'name': '91-120', 'stop': '2018-11-09', 'start': '2018-10-11'}
{'name': '+120', 'stop': '2018-10-10', 'start': False}
```

opw-1886633

closes #27294
  • Loading branch information
nim-odoo committed Oct 10, 2018
1 parent 37d2024 commit 3c4f853
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions addons/account/report/account_aged_partner_balance.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
# Do an invoice and a payment and unreconcile. The amount will be nullified # Do an invoice and a payment and unreconcile. The amount will be nullified
# By default, the partner wouldn't appear in this report. # By default, the partner wouldn't appear in this report.
# The context key allow it to appear # The context key allow it to appear
# In case of a period_length of 30 days as of 2019-02-08, we want the following periods:
# Name Stop Start
# 1 - 30 : 2019-02-07 - 2019-01-09
# 31 - 60 : 2019-01-08 - 2018-12-10
# 61 - 90 : 2018-12-09 - 2018-11-10
# 91 - 120 : 2018-11-09 - 2018-10-11
# +120 : 2018-10-10
periods = {} periods = {}
start = datetime.strptime(date_from, "%Y-%m-%d") start = datetime.strptime(date_from, "%Y-%m-%d")
for i in range(5)[::-1]: for i in range(5)[::-1]:
stop = start - relativedelta(days=period_length) stop = start - relativedelta(days=period_length)
period_name = str((5-(i+1)) * period_length + 1) + '-' + str((5-i) * period_length)
period_stop = (start - relativedelta(days=1)).strftime('%Y-%m-%d')
if i == 0:
period_name = '+' + str(4 * period_length)
periods[str(i)] = { periods[str(i)] = {
'name': (i!=0 and (str((5-(i+1)) * period_length) + '-' + str((5-i) * period_length)) or ('+'+str(4 * period_length))), 'name': period_name,
'stop': start.strftime('%Y-%m-%d'), 'stop': period_stop,
'start': (i!=0 and stop.strftime('%Y-%m-%d') or False), 'start': (i!=0 and stop.strftime('%Y-%m-%d') or False),
} }
start = stop - relativedelta(days=1) start = stop


res = [] res = []
total = [] total = []
Expand Down Expand Up @@ -77,7 +88,7 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
WHERE (l.account_id = account_account.id) AND (l.move_id = am.id) WHERE (l.account_id = account_account.id) AND (l.move_id = am.id)
AND (am.state IN %s) AND (am.state IN %s)
AND (account_account.internal_type IN %s) AND (account_account.internal_type IN %s)
AND (COALESCE(l.date_maturity,l.date) > %s)\ AND (COALESCE(l.date_maturity,l.date) >= %s)\
AND ((l.partner_id IN %s) OR (l.partner_id IS NULL)) AND ((l.partner_id IN %s) OR (l.partner_id IS NULL))
AND (l.date <= %s) AND (l.date <= %s)
AND l.company_id IN %s''' AND l.company_id IN %s'''
Expand Down
2 changes: 1 addition & 1 deletion addons/account/tests/test_reconciliation.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def create_invoice_partner(self, type='out_invoice', invoice_amount=50, currency
def test_aged_report(self): def test_aged_report(self):
AgedReport = self.env['report.account.report_agedpartnerbalance'].with_context(include_nullified_amount=True) AgedReport = self.env['report.account.report_agedpartnerbalance'].with_context(include_nullified_amount=True)
account_type = ['receivable'] account_type = ['receivable']
report_date_to = time.strftime('%Y') + '-07-15' report_date_to = time.strftime('%Y') + '-07-16'
partner = self.env['res.partner'].create({'name': 'AgedPartner'}) partner = self.env['res.partner'].create({'name': 'AgedPartner'})
currency = self.env.user.company_id.currency_id currency = self.env.user.company_id.currency_id


Expand Down

0 comments on commit 3c4f853

Please sign in to comment.