Skip to content

Commit

Permalink
account: search on parent_state instead of move_id.state
Browse files Browse the repository at this point in the history
By searching on account.move.line parent_state instead
of move_id.state, we avoid a join in many circumstances
and allow the database to benefit on an index on
company_id+parent_state to optimize several
queries, such as the default filter on the Journal Items
menu which shows posted items.

closes #80701

Signed-off-by: Quentin De Paoli <qdp@odoo.com>
  • Loading branch information
sbidoul committed Dec 2, 2021
1 parent 0cb9d03 commit c2a72c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions addons/account/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def _get_journal_bank_account_balance(self, domain=None):
domain = (domain or []) + [
('account_id', 'in', tuple(self.default_account_id.ids)),
('display_type', 'not in', ('line_section', 'line_note')),
('move_id.state', '!=', 'cancel'),
('parent_state', '!=', 'cancel'),
]
query = self.env['account.move.line']._where_calc(domain)
tables, where_clause, where_params = query.get_sql()
Expand Down Expand Up @@ -734,7 +734,7 @@ def _get_journal_outstanding_payments_account_balance(self, domain=None, date=No
domain = (domain or []) + [
('account_id', 'in', tuple(accounts.ids)),
('display_type', 'not in', ('line_section', 'line_note')),
('move_id.state', '!=', 'cancel'),
('parent_state', '!=', 'cancel'),
('reconciled', '=', False),
('journal_id', '=', self.id),
]
Expand Down
6 changes: 3 additions & 3 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ def _compute_payments_widget_to_reconcile_info(self):

domain = [
('account_id', 'in', pay_term_lines.account_id.ids),
('move_id.state', '=', 'posted'),
('parent_state', '=', 'posted'),
('partner_id', '=', move.commercial_partner_id.id),
('reconciled', '=', False),
'|', ('amount_residual', '!=', 0.0), ('amount_residual_currency', '!=', 0.0),
Expand Down Expand Up @@ -5044,7 +5044,7 @@ def _query_get(self, domain=None):

state = context.get('state')
if state and state.lower() != 'all':
domain += [('move_id.state', '=', state)]
domain += [('parent_state', '=', state)]

if context.get('company_id'):
domain += [('company_id', '=', context['company_id'])]
Expand Down Expand Up @@ -5079,7 +5079,7 @@ def _query_get(self, domain=None):
tables = ''
if domain:
domain.append(('display_type', 'not in', ('line_section', 'line_note')))
domain.append(('move_id.state', '!=', 'cancel'))
domain.append(('parent_state', '!=', 'cancel'))

query = self._where_calc(domain)

Expand Down

0 comments on commit c2a72c2

Please sign in to comment.