Skip to content

Commit 8c914ec

Browse files
committed
Merge PR #1836 into 18.0
Signed-off-by jbaudoux
2 parents d63eef4 + 38c95ad commit 8c914ec

File tree

16 files changed

+761
-0
lines changed

16 files changed

+761
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
===========================
2+
Stock Picking Group By Base
3+
===========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:8218ebe960326563eb49a0e07c94d756d899c63e25e48bc6d6662475b6b8e660
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_group_by_base
21+
:alt: OCA/stock-logistics-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_picking_group_by_base
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Technical module in order to add a database index for picking grouping
32+
modules.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Usage
40+
=====
41+
42+
Further modules need to implement this on stock.picking model:
43+
44+
.. code:: python
45+
46+
def init(self):
47+
"""
48+
This has to be called in every overriding module
49+
"""
50+
self._create_index_for_grouping()
51+
52+
53+
@api.model
54+
def _get_index_for_grouping_fields(self):
55+
"""
56+
This tuple is intended to be overriden in order to add fields
57+
used in groupings
58+
"""
59+
return [
60+
"partner_id",
61+
"location_id",
62+
"location_dest_id",
63+
"picking_type_id",
64+
]
65+
66+
Bug Tracker
67+
===========
68+
69+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/issues>`_.
70+
In case of trouble, please check there if your issue has already been reported.
71+
If you spotted it first, help us to smash it by providing a detailed and welcomed
72+
`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**>`_.
73+
74+
Do not contact contributors directly about support or help with technical issues.
75+
76+
Credits
77+
=======
78+
79+
Authors
80+
-------
81+
82+
* ACSONE SA/NV
83+
84+
Contributors
85+
------------
86+
87+
- Denis Roussel <[email protected]>
88+
- Tuan Nguyen <[email protected]>
89+
90+
Maintainers
91+
-----------
92+
93+
This module is maintained by the OCA.
94+
95+
.. image:: https://odoo-community.org/logo.png
96+
:alt: Odoo Community Association
97+
:target: https://odoo-community.org
98+
99+
OCA, or the Odoo Community Association, is a nonprofit organization whose
100+
mission is to support the collaborative development of Odoo features and
101+
promote its widespread use.
102+
103+
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.
104+
105+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from .hooks import uninstall_hook
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2022 ACSONE SA/NV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Stock Picking Group By Base",
6+
"summary": """
7+
Allows to define a way to create index on extensible domain""",
8+
"version": "18.0.1.0.0",
9+
"license": "AGPL-3",
10+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/stock-logistics-workflow",
12+
"depends": ["stock"],
13+
"uninstall_hook": "uninstall_hook",
14+
}

stock_picking_group_by_base/hooks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2020 ACSONE SA/NV
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from psycopg2.extensions import AsIs
4+
5+
6+
def uninstall_hook(env):
7+
"""
8+
This method will remove created index
9+
"""
10+
index_name = "stock_picking_groupby_key_index"
11+
env.cr.execute(
12+
"DROP INDEX IF EXISTS %(index_name)s", dict(index_name=AsIs(index_name))
13+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * stock_picking_group_by_base
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2023-11-17 09:33+0000\n"
10+
"Last-Translator: mymage <[email protected]>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 4.17\n"
18+
19+
#. module: stock_picking_group_by_base
20+
#: model:ir.model,name:stock_picking_group_by_base.model_stock_picking
21+
msgid "Transfer"
22+
msgstr "Trasferimento"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * stock_picking_group_by_base
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: stock_picking_group_by_base
17+
#: model:ir.model,name:stock_picking_group_by_base.model_stock_picking
18+
msgid "Transfer"
19+
msgstr ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import stock_picking
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright 2016-2020 Jacques-Etienne Baudoux (BCIM) <[email protected]>
2+
# Copyright 2019-2020 Camptocamp
3+
# Copyright 2020 ACSONE SA/NV
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5+
import logging
6+
7+
from psycopg2.errors import LockNotAvailable
8+
9+
from odoo import api, models
10+
from odoo.tools import SQL
11+
12+
_logger = logging.getLogger(__name__)
13+
14+
15+
class StockPicking(models.Model):
16+
_inherit = "stock.picking"
17+
18+
@api.model
19+
def _get_index_for_grouping_fields(self):
20+
"""
21+
This tuple is intended to be overriden in order to add fields
22+
used in groupings
23+
"""
24+
return [
25+
"partner_id",
26+
"location_id",
27+
"location_dest_id",
28+
"picking_type_id",
29+
]
30+
31+
@api.model
32+
def _get_index_for_grouping_condition(self):
33+
return """
34+
WHERE printed is False
35+
AND state in (
36+
'draft', 'confirmed', 'waiting',
37+
'partially_available', 'assigned'
38+
)
39+
"""
40+
41+
@api.model
42+
def _create_index_for_grouping(self):
43+
# create index for the domain expressed into the
44+
# stock_move._assign_picking_group_domain method
45+
index_name = "stock_picking_groupby_key_index"
46+
47+
try:
48+
self.env.cr.execute(
49+
SQL(
50+
"DROP INDEX IF EXISTS %(index_name)s",
51+
index_name=SQL.identifier(index_name),
52+
)
53+
)
54+
55+
self.env.cr.execute(
56+
SQL(
57+
"""
58+
CREATE INDEX %(index_name)s
59+
ON %(table_name)s (%(fields)s)
60+
%(where)s
61+
""",
62+
index_name=SQL.identifier(index_name),
63+
table_name=SQL.identifier(self._table),
64+
fields=SQL(", ").join(
65+
[
66+
SQL.identifier(field)
67+
for field in self._get_index_for_grouping_fields()
68+
]
69+
),
70+
where=SQL(self._get_index_for_grouping_condition()),
71+
)
72+
)
73+
except LockNotAvailable as e:
74+
# Do nothing and let module load
75+
_logger.warning(
76+
self.env._(
77+
"Impossible to create index in stock_picking_group_by_base module"
78+
" due to DB Lock problem (%s)",
79+
e,
80+
)
81+
)
82+
except Exception:
83+
raise
84+
85+
def init(self):
86+
"""
87+
This has to be called in every overriding module
88+
"""
89+
self._create_index_for_grouping()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Denis Roussel \<<[email protected]>\>
2+
- Tuan Nguyen \<<[email protected]>\>

0 commit comments

Comments
 (0)