From a96757e19cfa3df6ac60c6f4304874a4eb7334e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20T=C3=B3th?= Date: Thu, 29 Oct 2020 10:25:34 +0000 Subject: [PATCH] [FIX] Fix journal dashboard late counter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: The journal dashboard show wrong values for the late invoices. Background details: The filter for the "Late" invoices is not in sync with the sql query in the dashboard python code. The filter searchs for the invoice_date_due field while the sql searchs for the date field. closes odoo/odoo#73992 X-original-commit: f1e9e756b8806aca92fda4d528fd0b23842e967a Signed-off-by: William André (wan) --- .../models/account_journal_dashboard.py | 35 ++++++++++--------- .../views/account_journal_dashboard_view.xml | 11 ++++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index dd48fc7fdcb..9a620e00deb 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -275,23 +275,10 @@ class account_journal(models.Model): self.env.cr.execute(query, query_args) query_results_drafts = self.env.cr.dictfetchall() - today = fields.Date.context_today(self) - query = ''' - SELECT - (CASE WHEN move_type IN ('out_refund', 'in_refund') THEN -1 ELSE 1 END) * amount_residual AS amount_total, - currency_id AS currency, - move_type, - invoice_date, - company_id - FROM account_move move - WHERE journal_id = %s - AND date <= %s - AND state = 'posted' - AND payment_state in ('not_paid', 'partial') - AND move_type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'); - ''' - self.env.cr.execute(query, (self.id, today)) + (query, query_args) = self._get_late_bills_query() + self.env.cr.execute(query, query_args) late_query_results = self.env.cr.dictfetchall() + curr_cache = {} (number_waiting, sum_waiting) = self._count_results_and_sum_amounts(query_results_to_pay, currency, curr_cache=curr_cache) (number_draft, sum_draft) = self._count_results_and_sum_amounts(query_results_drafts, currency, curr_cache=curr_cache) @@ -371,6 +358,22 @@ class account_journal(models.Model): AND move.move_type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'); ''', {'journal_id': self.id}) + def _get_late_bills_query(self): + return """ + SELECT + (CASE WHEN move_type IN ('out_refund', 'in_refund') THEN -1 ELSE 1 END) * amount_residual AS amount_total, + currency_id AS currency, + move_type, + invoice_date, + company_id + FROM account_move move + WHERE journal_id = %(journal_id)s + AND invoice_date_due <= %(today)s + AND state = 'posted' + AND payment_state in ('not_paid', 'partial') + AND move_type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'); + """, {'journal_id': self.id, 'today': fields.Date.context_today(self)} + def _count_results_and_sum_amounts(self, results_dict, target_currency, curr_cache=None): """ Loops on a query result to count the total number of invoices and sum their amount_total field (expressed in the given target currency). diff --git a/addons/account/views/account_journal_dashboard_view.xml b/addons/account/views/account_journal_dashboard_view.xml index dad09df46d4..e524cf1620d 100644 --- a/addons/account/views/account_journal_dashboard_view.xml +++ b/addons/account/views/account_journal_dashboard_view.xml @@ -340,6 +340,17 @@ +