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.

30 lines
1.2 KiB

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