[FIX] Fix journal dashboard late counter
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) <wan@odoo.com>
This commit is contained in:
committed by
william-andre
parent
38bff3d7f5
commit
a96757e19c
@@ -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).
|
||||
|
||||
@@ -340,6 +340,17 @@
|
||||
<span><t t-esc="dashboard.sum_waiting"/></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" t-if="dashboard.number_late">
|
||||
<div class="col overflow-hidden text-left">
|
||||
<a type="object" name="open_action" context="{'search_default_late': '1'}">
|
||||
<span t-if="journal_type == 'sale'" title="Late Invoices"><t t-esc="dashboard.number_late"/> Late Invoices</span>
|
||||
<span t-if="journal_type == 'purchase'" title="Late Bills"><t t-esc="dashboard.number_late"/> Late Bills</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-auto text-right">
|
||||
<span><t t-esc="dashboard.sum_late"/></span>
|
||||
</div>
|
||||
</div>
|
||||
<t t-if="dashboard.number_to_check > 0">
|
||||
<div class="row">
|
||||
<div class="col overflow-hidden text-left">
|
||||
|
||||
Reference in New Issue
Block a user