From ee281168e38ac324fbf46a1a5e9b1d8af0c22188 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Mon, 26 Mar 2018 13:27:53 +0200 Subject: [PATCH] [FIX] account: substract total amount of credit notes in the counts reported on dashboard The refactoring made for v11 at commit 414ea47fd53306744b8f47f36607311713689068 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) --- addons/account/models/account_journal_dashboard.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index 9ed3f9f65d2..7f3659005de 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -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