Skip to content

Commit

Permalink
Merge PR #1836 into 18.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Jan 31, 2025
2 parents d63eef4 + 38c95ad commit 8c914ec
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 0 deletions.
105 changes: 105 additions & 0 deletions stock_picking_group_by_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
===========================
Stock Picking Group By Base
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8218ebe960326563eb49a0e07c94d756d899c63e25e48bc6d6662475b6b8e660
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_group_by_base
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_picking_group_by_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Technical module in order to add a database index for picking grouping
modules.

**Table of contents**

.. contents::
:local:

Usage
=====

Further modules need to implement this on stock.picking model:

.. code:: python
def init(self):
"""
This has to be called in every overriding module
"""
self._create_index_for_grouping()
@api.model
def _get_index_for_grouping_fields(self):
"""
This tuple is intended to be overriden in order to add fields
used in groupings
"""
return [
"partner_id",
"location_id",
"location_dest_id",
"picking_type_id",
]
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_group_by_base%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Denis Roussel <[email protected]>
- Tuan Nguyen <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_group_by_base>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_picking_group_by_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import uninstall_hook
14 changes: 14 additions & 0 deletions stock_picking_group_by_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Picking Group By Base",
"summary": """
Allows to define a way to create index on extensible domain""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"uninstall_hook": "uninstall_hook",
}
13 changes: 13 additions & 0 deletions stock_picking_group_by_base/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from psycopg2.extensions import AsIs


def uninstall_hook(env):
"""
This method will remove created index
"""
index_name = "stock_picking_groupby_key_index"
env.cr.execute(
"DROP INDEX IF EXISTS %(index_name)s", dict(index_name=AsIs(index_name))
)
22 changes: 22 additions & 0 deletions stock_picking_group_by_base/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_group_by_base
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-11-17 09:33+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: stock_picking_group_by_base
#: model:ir.model,name:stock_picking_group_by_base.model_stock_picking
msgid "Transfer"
msgstr "Trasferimento"
19 changes: 19 additions & 0 deletions stock_picking_group_by_base/i18n/stock_picking_group_by_base.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_group_by_base
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_picking_group_by_base
#: model:ir.model,name:stock_picking_group_by_base.model_stock_picking
msgid "Transfer"
msgstr ""
1 change: 1 addition & 0 deletions stock_picking_group_by_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking
89 changes: 89 additions & 0 deletions stock_picking_group_by_base/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2016-2020 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# 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 odoo import api, models
from odoo.tools import SQL

_logger = logging.getLogger(__name__)


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

@api.model
def _get_index_for_grouping_fields(self):
"""
This tuple is intended to be overriden in order to add fields
used in groupings
"""
return [
"partner_id",
"location_id",
"location_dest_id",
"picking_type_id",
]

@api.model
def _get_index_for_grouping_condition(self):
return """
WHERE printed is False
AND state in (
'draft', 'confirmed', 'waiting',
'partially_available', 'assigned'
)
"""

@api.model
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"

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

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

def init(self):
"""
This has to be called in every overriding module
"""
self._create_index_for_grouping()
3 changes: 3 additions & 0 deletions stock_picking_group_by_base/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions stock_picking_group_by_base/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Denis Roussel \<<[email protected]>\>
- Tuan Nguyen \<<[email protected]>\>
2 changes: 2 additions & 0 deletions stock_picking_group_by_base/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Technical module in order to add a database index for picking grouping
modules.
23 changes: 23 additions & 0 deletions stock_picking_group_by_base/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Further modules need to implement this on stock.picking model:

``` python
def init(self):
"""
This has to be called in every overriding module
"""
self._create_index_for_grouping()


@api.model
def _get_index_for_grouping_fields(self):
"""
This tuple is intended to be overriden in order to add fields
used in groupings
"""
return [
"partner_id",
"location_id",
"location_dest_id",
"picking_type_id",
]
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8c914ec

Please sign in to comment.