You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-
  4. from odoo import api, models
  5. class AccountMoveLine(models.Model):
  6. _inherit = 'account.move.line'
  7. @api.model_cr
  8. def init(self):
  9. """
  10. The join between accounts_partners subquery and account_move_line
  11. can be heavy to compute on big databases.
  12. Join sample:
  13. JOIN
  14. account_move_line ml
  15. ON ap.account_id = ml.account_id
  16. AND ml.date < '2018-12-30'
  17. AND ap.partner_id = ml.partner_id
  18. AND ap.include_initial_balance = TRUE
  19. By adding the following index, performances are strongly increased.
  20. :return:
  21. """
  22. self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = '
  23. '%s',
  24. ('account_move_line_account_id_partner_id_index',))
  25. if not self._cr.fetchone():
  26. self._cr.execute("""
  27. CREATE INDEX account_move_line_account_id_partner_id_index
  28. ON account_move_line (account_id, partner_id)""")