[FIX] account: substract total amount of credit notes in the counts reported on dashboard

The refactoring made for v11 at commit 414ea47fd5 summed the amounts of every invoice, credit note or not. This lead to wrong amounts in dashboard, as credit notes have positive total amounts, just like regular invoices.

(Fixes this ticket: https://www.odoo.com/web#id=1828003&view_type=form&model=project.task&action=333&active_id=49&menu_id=4720)
This commit is contained in:
Olivier Colson
2018-03-26 13:32:52 +02:00
parent bae7e32e4b
commit ee281168e3
@@ -224,7 +224,7 @@ class account_journal(models.Model):
data as its first element, and the arguments dictionary to use to run
it as its second.
"""
return ("""SELECT state, amount_total, currency_id AS currency
return ("""SELECT state, amount_total, currency_id AS currency, type
FROM account_invoice
WHERE journal_id = %(journal_id)s AND state = 'open';""", {'journal_id':self.id})
@@ -234,7 +234,7 @@ class account_journal(models.Model):
gather the bills in draft state data, and the arguments
dictionary to use to run it as its second.
"""
return ("""SELECT state, amount_total, currency_id AS currency
return ("""SELECT state, amount_total, currency_id AS currency, type
FROM account_invoice
WHERE journal_id = %(journal_id)s AND state = 'draft';""", {'journal_id':self.id})
@@ -247,7 +247,9 @@ class account_journal(models.Model):
for result in results_dict:
cur = self.env['res.currency'].browse(result.get('currency'))
rslt_count += 1
rslt_sum += cur.compute(result.get('amount_total'), target_currency)
type_factor = result.get('type') in ('in_refund', 'out_refund') and -1 or 1
rslt_sum += type_factor * cur.compute(result.get('amount_total'), target_currency)
return (rslt_count, rslt_sum)
@api.multi