Skip to content

Commit

Permalink
Merge PR #1328 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rousseldenis
  • Loading branch information
OCA-git-bot committed Sep 23, 2024
2 parents 13ba46d + 6037d72 commit 671b847
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions stock_picking_group_by_base/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# Copyright 2019-2020 Camptocamp
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from psycopg2.errors import LockNotAvailable
from psycopg2.extensions import AsIs

from odoo import api, models

_logger = logging.getLogger(__name__)


class StockPicking(models.Model):

Expand Down Expand Up @@ -36,25 +41,36 @@ def _create_index_for_grouping(self):
# create index for the domain expressed into the
# stock_move._assign_picking_group_domain method
index_name = "stock_picking_groupby_key_index"
self.env.cr.execute(
"DROP INDEX IF EXISTS %(index_name)s", dict(index_name=AsIs(index_name))
)

self.env.cr.execute(
"""
CREATE INDEX %(index_name)s
ON %(table_name)s %(fields)s
%(where)s
""",
dict(
index_name=AsIs(index_name),
table_name=AsIs(self._table),
fields=tuple(
[AsIs(field) for field in self._get_index_for_grouping_fields()]

try:
self.env.cr.execute(
"DROP INDEX IF EXISTS %(index_name)s", dict(index_name=AsIs(index_name))
)

self.env.cr.execute(
"""
CREATE INDEX %(index_name)s
ON %(table_name)s %(fields)s
%(where)s
""",
dict(
index_name=AsIs(index_name),
table_name=AsIs(self._table),
fields=tuple(
[AsIs(field) for field in self._get_index_for_grouping_fields()]
),
where=AsIs(self._get_index_for_grouping_condition()),
),
where=AsIs(self._get_index_for_grouping_condition()),
),
)
)
except LockNotAvailable as e:
# Do nothing and let module load
_logger.warning(
"Impossible to create index in stock_picking_group_by_base module"
" due to DB Lock problem (%s)",
e,
)
except Exception:
raise

def init(self):
"""
Expand Down

0 comments on commit 671b847

Please sign in to comment.