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.

40 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. def init(self):
  7. """
  8. The join between accounts_partners subquery and account_move_line
  9. can be heavy to compute on big databases.
  10. Join sample:
  11. JOIN
  12. account_move_line ml
  13. ON ap.account_id = ml.account_id
  14. AND ml.date < '2018-12-30'
  15. AND ap.partner_id = ml.partner_id
  16. AND ap.include_initial_balance = TRUE
  17. By adding the following index, performances are strongly increased.
  18. :return:
  19. """
  20. self._cr.execute(
  21. "SELECT indexname FROM pg_indexes WHERE indexname = " "%s",
  22. ("account_move_line_account_id_partner_id_index",),
  23. )
  24. if not self._cr.fetchone():
  25. self._cr.execute(
  26. """
  27. CREATE INDEX account_move_line_account_id_partner_id_index
  28. ON account_move_line (account_id, partner_id)"""
  29. )
  30. @api.model
  31. def search_count(self, args):
  32. # In Big DataBase every time you change the domain widget this method
  33. # takes a lot of time. This improves performance
  34. if self.env.context.get("skip_search_count"):
  35. return 0
  36. return super(AccountMoveLine, self).search_count(args)