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.

38 lines
1.5 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)""")
  28. @api.model
  29. def search_count(self, args):
  30. # In Big DataBase every time you change the domain widget this method
  31. # takes a lot of time. This improves performance
  32. if self.env.context.get("skip_search_count"):
  33. return 0
  34. return super(AccountMoveLine, self).search_count(args)