From 7d3dde98a35473f78688b1d00b9b8f0c30887612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Wed, 30 Aug 2017 18:51:31 +0200 Subject: [PATCH] [IMP] account_tax_balance: add index This indexes improve the display time of account_tax_balance by a factor of 10 on a database with 1M move lines. --- account_tax_balance/__manifest__.py | 2 +- account_tax_balance/models/__init__.py | 1 + .../models/account_move_line.py | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 account_tax_balance/models/account_move_line.py diff --git a/account_tax_balance/__manifest__.py b/account_tax_balance/__manifest__.py index 4ae50fd4..efc19336 100644 --- a/account_tax_balance/__manifest__.py +++ b/account_tax_balance/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Tax Balance", "summary": "Compute tax balances based on date range", - "version": "10.0.1.1.0", + "version": "10.0.1.1.1", "category": "Accounting & Finance", "website": "https://www.agilebg.com/", "author": "Agile Business Group, Therp BV, Tecnativa, ACSONE SA/NV, " diff --git a/account_tax_balance/models/__init__.py b/account_tax_balance/models/__init__.py index b78e51cd..b2a132ed 100644 --- a/account_tax_balance/models/__init__.py +++ b/account_tax_balance/models/__init__.py @@ -4,3 +4,4 @@ from . import account_move from . import account_tax +from . import account_move_line diff --git a/account_tax_balance/models/account_move_line.py b/account_tax_balance/models/account_move_line.py new file mode 100644 index 00000000..d4c52465 --- /dev/null +++ b/account_tax_balance/models/account_move_line.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountMoveLine(models.Model): + + _inherit = 'account.move.line' + + @api.model_cr + def init(self): + res = super(AccountMoveLine, self).init() + self._cr.execute(""" + SELECT indexname FROM pg_indexes + WHERE indexname = 'account_move_line_date_tax_line_id_idx' + """) + if not self._cr.fetchone(): + self._cr.execute(""" + CREATE INDEX account_move_line_date_tax_line_id_idx + ON account_move_line (date, tax_line_id) + """) + return res