Skip to content

Commit 2743d8f

Browse files
[FIX] account: fix accounting dashboard bar graphs
The Customer Invoices and Vendor Bills bar graphs in the accounting dashboard skip empty weeks so the following weeks will be displayed sooner Steps to reproduce: 1. Install Accounting 2. Go to the accounting dashboard 3. The bar graph of Customer Invoices is not correct: it ends with empty weeks but they should be in between the data Solution: Choose where each query result should be by using the aggr_date to find in which week the data is included Problem: The SQL query didn't return any date for empty weeks so sorting the result by date would leave some weeks out of the bar graph opw-2844159 closes odoo#91441 Signed-off-by: Cedric Snauwaert <[email protected]>
1 parent 72513e9 commit 2743d8f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

addons/account/models/account_journal_dashboard.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def build_graph_data(date, amount):
138138

139139
def get_bar_graph_datas(self):
140140
data = []
141-
today = fields.Datetime.now(self)
141+
today = fields.Date.today()
142142
data.append({'label': _('Due'), 'value':0.0, 'type': 'past'})
143143
day_of_week = int(format_datetime(today, 'e', locale=get_lang(self.env).code))
144144
first_day_of_week = today + timedelta(days=-day_of_week+1)
@@ -160,24 +160,29 @@ def get_bar_graph_datas(self):
160160
(select_sql_clause, query_args) = self._get_bar_graph_select_query()
161161
query = ''
162162
start_date = (first_day_of_week + timedelta(days=-7))
163+
weeks = []
163164
for i in range(0,6):
164165
if i == 0:
165166
query += "("+select_sql_clause+" and invoice_date_due < '"+start_date.strftime(DF)+"')"
167+
weeks.append((start_date.min, start_date))
166168
elif i == 5:
167169
query += " UNION ALL ("+select_sql_clause+" and invoice_date_due >= '"+start_date.strftime(DF)+"')"
170+
weeks.append((start_date, start_date.max))
168171
else:
169172
next_date = start_date + timedelta(days=7)
170173
query += " UNION ALL ("+select_sql_clause+" and invoice_date_due >= '"+start_date.strftime(DF)+"' and invoice_date_due < '"+next_date.strftime(DF)+"')"
174+
weeks.append((start_date, next_date))
171175
start_date = next_date
172176
# Ensure results returned by postgres match the order of data list
173-
query += " ORDER BY aggr_date ASC"
174177
self.env.cr.execute(query, query_args)
175178
query_results = self.env.cr.dictfetchall()
176179
is_sample_data = True
177180
for index in range(0, len(query_results)):
178181
if query_results[index].get('aggr_date') != None:
179182
is_sample_data = False
180-
data[index]['value'] = query_results[index].get('total')
183+
aggr_date = query_results[index]['aggr_date']
184+
week_index = next(i for i in range(0, len(weeks)) if weeks[i][0] <= aggr_date < weeks[i][1])
185+
data[week_index]['value'] = query_results[index].get('total')
181186

182187
[graph_title, graph_key] = self._graph_title_and_key()
183188

0 commit comments

Comments
 (0)