[IMP] account: search on parent_state instead of move_id.state

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 odoo/odoo#82504

X-original-commit: ef61db1cf8ebf1ab11e5dfdd439256d0607edba8
Signed-off-by: Quentin De Paoli <qdp@odoo.com>
Signed-off-by: Florian Gilbert <flg@odoo.com>
This commit is contained in:
Stéphane Bidoul
2022-01-11 06:48:27 +00:00
committed by Florian(flg)
parent 6ae67acd0e
commit 9224313e34
2 changed files with 5 additions and 5 deletions
@@ -245,9 +245,9 @@ class account_journal(models.Model):
last_balance = last_statement.balance_end
has_at_least_one_statement = bool(last_statement)
bank_account_balance, nb_lines_bank_account_balance = self._get_journal_bank_account_balance(
domain=[('move_id.state', '=', 'posted')])
domain=[('parent_state', '=', 'posted')])
outstanding_pay_account_balance, nb_lines_outstanding_pay_account_balance = self._get_journal_outstanding_payments_account_balance(
domain=[('move_id.state', '=', 'posted')])
domain=[('parent_state', '=', 'posted')])
self._cr.execute('''
SELECT COUNT(st_line.id)
+3 -3
View File
@@ -349,8 +349,8 @@
<field name="tax_line_id" string="Originator Tax"/>
<field name="reconcile_model_id"/>
<separator/>
<filter string="Unposted" name="unposted" domain="[('move_id.state', '=', 'draft')]" help="Unposted Journal Items"/>
<filter string="Posted" name="posted" domain="[('move_id.state', '=', 'posted')]" help="Posted Journal Items"/>
<filter string="Unposted" name="unposted" domain="[('parent_state', '=', 'draft')]" help="Unposted Journal Items"/>
<filter string="Posted" name="posted" domain="[('parent_state', '=', 'posted')]" help="Posted Journal Items"/>
<separator/>
<filter string="To Check" name="to_check" domain="[('move_id.to_check', '=', True)]"/>
<separator/>
@@ -1456,7 +1456,7 @@
<field name="context">{'journal_type':'general', 'search_default_posted':1}</field>
<field name="name">Journal Items</field>
<field name="res_model">account.move.line</field>
<field name="domain">[('display_type', 'not in', ('line_section', 'line_note'))]</field>
<field name="domain">[('display_type', 'not in', ('line_section', 'line_note')), ('parent_state', '!=', 'cancel')]</field>
<field name="view_id" ref="view_move_line_tree"/>
<field name="view_mode">tree,pivot,graph,form,kanban</field>
</record>