Skip to content

Commit

Permalink
[ADD] new grap_index module
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Mar 31, 2023
1 parent 684a0df commit 81db299
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 0 deletions.
Empty file added grap_index/README.rst
Empty file.
2 changes: 2 additions & 0 deletions grap_index/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import drop_indexes
21 changes: 21 additions & 0 deletions grap_index/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "GRAP - Custom Index",
"summary": "Add Extra postgresql Indexes",
"version": "12.0.1.0.1",
"category": "GRAP - Custom",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-custom",
"license": "AGPL-3",
"depends": [
# Odoo
"point_of_sale",
"purchase_stock",
"sale_stock",
],
"installable": True,
"uninstall_hook": "drop_indexes",
}
25 changes: 25 additions & 0 deletions grap_index/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging

from psycopg2.extensions import AsIs

logger = logging.getLogger(__name__)


def drop_indexes(cr, registry):
indexes = [
("account_bank_statement_line", "pos_statement_id"),
("pos_order", "returned_order_id"),
("pos_order_line", "order_id"),
("stock_move", "created_purchase_line_id"),
("stock_move_line", "picking_id"),
("stock_picking", "group_id"),
("stock_picking", "sale_id"),
]

for index in indexes:
index_name = "%s_%s_index" % (index[0], index[1])
logger.info("dropping posgresql index %s" % index_name)
cr.execute("DROP INDEX IF EXISTS %s;", (AsIs(index_name),))
Empty file added grap_index/i18n/fr.po
Empty file.
6 changes: 6 additions & 0 deletions grap_index/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import account_bank_statement_line
from . import stock_move
from . import stock_move_line
from . import stock_picking
from . import pos_order
from . import pos_order_line
11 changes: 11 additions & 0 deletions grap_index/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"

pos_statement_id = fields.Many2one(index=True)
13 changes: 13 additions & 0 deletions grap_index/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class PosOrder(models.Model):
_inherit = "pos.order"

returned_order_id = fields.Many2one(index=True)

company_id = fields.Many2one(index=True)
11 changes: 11 additions & 0 deletions grap_index/models/pos_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class PosOrderLine(models.Model):
_inherit = "pos.order.line"

order_id = fields.Many2one(index=True)
13 changes: 13 additions & 0 deletions grap_index/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class StockMove(models.Model):
_inherit = "stock.move"

created_purchase_line_id = fields.Many2one(index=True)

inventory_id = fields.Many2one(index=True)
11 changes: 11 additions & 0 deletions grap_index/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

picking_id = fields.Many2one(index=True)
13 changes: 13 additions & 0 deletions grap_index/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class StockPicking(models.Model):
_inherit = "stock.picking"

group_id = fields.Many2one(index=True)

sale_id = fields.Many2one(index=True)
1 change: 1 addition & 0 deletions grap_index/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)
21 changes: 21 additions & 0 deletions grap_index/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This module add extra postgresql indexes to speed up SELECT queries.

**"Purchase" performance**

- ``stock_move``, on ``created_purchase_line_id``

**"Sale" performance**

- ``stock_picking``, on ``sale_id``

**"Stock" performance**

- ``stock_move``, on ``inventory_id``
- ``stock_move_line``, on ``picking_id``
- ``stock_picking``, on ``group_id``

**"Point of Sale" performance**

- ``account_bank_statement_line``, on ``pos_statement_id``
- ``pos_order``, on ``returned_order_id`` and ``company_id``
- ``pos_order_line``, on ``order_id``
1 change: 1 addition & 0 deletions setup/grap_index/odoo/addons/grap_index
6 changes: 6 additions & 0 deletions setup/grap_index/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 81db299

Please sign in to comment.