Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] new grap_index module #307

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added grap_index/README.rst
Empty file.
2 changes: 2 additions & 0 deletions grap_index/__init__.py
@@ -0,0 +1,2 @@
from . import models
from .hooks import drop_indexes
21 changes: 21 additions & 0 deletions grap_index/__manifest__.py
@@ -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
@@ -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 = {

Check warning on line 12 in grap_index/hooks.py

View check run for this annotation

Codecov / codecov/patch

grap_index/hooks.py#L12

Added line #L12 was not covered by tests
"account_bank_statement_line": ["pos_statement_id"],
"pos_order": ["returned_order_id", "company_id"],
"pos_order_line": ["order_id"],
"stock_move": ["created_purchase_line_id", "inventory_id"],
"stock_move_line": ["picking_id"],
"stock_picking": ["group_id", "sale_id"],
}

for table_name, field_names in indexes.items():
for field_name in field_names:
index_name = "%s_%s_index" % (table_name, field_name)
logger.info("dropping posgresql index %s" % index_name)
cr.execute("DROP INDEX IF EXISTS %s;", (AsIs(index_name),))

Check warning on line 25 in grap_index/hooks.py

View check run for this annotation

Codecov / codecov/patch

grap_index/hooks.py#L23-L25

Added lines #L23 - L25 were not covered by tests
Empty file added grap_index/i18n/fr.po
Empty file.
6 changes: 6 additions & 0 deletions grap_index/models/__init__.py
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)
21 changes: 21 additions & 0 deletions grap_index/readme/DESCRIPTION.rst
@@ -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
@@ -0,0 +1,6 @@
import setuptools

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