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

[16.0] [MIG] stock_location_children #1802

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_location_children/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,
)
76 changes: 76 additions & 0 deletions stock_location_children/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
=======================
Stock location children
=======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |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--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_children
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_location_children
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/14.0
:alt: Try me on Runbot

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

This module adds a `children_ids` field on `stock.location` in order to compute
and store all the children for a `stock.location` and not only its first level
children as is the case for `child_ids`.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_location_children%0Aversion:%2014.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
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Akim Juillerat <[email protected]>
* Raphaël Reverdy <[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-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_location_children>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_location_children/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions stock_location_children/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Stock location children",
"summary": "Add relation between stock location and all its children",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock"],
}
31 changes: 31 additions & 0 deletions stock_location_children/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_location_children
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-26 06:00+0000\n"
"PO-Revision-Date: 2023-07-26 06:00+0000\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_location_children
#: model:ir.model.fields,help:stock_location_children.field_stock_location__children_ids
msgid "All the children (multi-level) stock location of this location"
msgstr "Tutte le ubicazioni derivate (multi livello) di questa ubicazione"

#. module: stock_location_children
#: model:ir.model.fields,field_description:stock_location_children.field_stock_location__children_ids
msgid "Children"
msgstr "Figli"

#. module: stock_location_children
#: model:ir.model,name:stock_location_children.model_stock_location
msgid "Inventory Locations"
msgstr "Ubicazioni di inventario"
31 changes: 31 additions & 0 deletions stock_location_children/i18n/stock_location_children.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_location_children
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-26 05:59+0000\n"
"PO-Revision-Date: 2023-07-26 05:59+0000\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_location_children
#: model:ir.model.fields,help:stock_location_children.field_stock_location__children_ids
msgid "All the children (multi-level) stock location of this location"
msgstr ""

#. module: stock_location_children
#: model:ir.model.fields,field_description:stock_location_children.field_stock_location__children_ids
msgid "Children"
msgstr ""

#. module: stock_location_children
#: model:ir.model,name:stock_location_children.model_stock_location
msgid "Inventory Locations"
msgstr ""
1 change: 1 addition & 0 deletions stock_location_children/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_location
45 changes: 45 additions & 0 deletions stock_location_children/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, fields, models


class StockLocation(models.Model):

_inherit = "stock.location"

children_ids = fields.Many2many(
"stock.location",
"stock_location_children_ids",
"parent_id",
"children_id",
compute="_compute_children_ids",
store=True,
help="All the children (multi-level) stock location of this location",
)

@api.depends("child_ids", "children_ids.child_ids")
def _compute_children_ids(self):
query = """SELECT sub.id, ARRAY_AGG(sl2.id) AS children
FROM stock_location sl2,
(
SELECT id, parent_path
FROM stock_location sl
) sub
WHERE sl2.parent_path LIKE sub.parent_path || '%%'
AND sl2.id != sub.id
AND sub.id IN %s
GROUP BY sub.id;
"""
self.flush_model(["location_id", "child_ids"])
self.env.cr.execute(query, (tuple(self.ids),))
rows = self.env.cr.dictfetchall()
for loc in self:
all_ids = []
for row in rows:
if row.get("id") == loc.id:
all_ids = row.get("children")
break
if all_ids:
loc.children_ids = [(6, 0, all_ids)]
else:
loc.children_ids = [(5, 0, 0)]
3 changes: 3 additions & 0 deletions stock_location_children/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Akim Juillerat <[email protected]>
* Raphaël Reverdy <[email protected]>
* Aiendry Sarkar <[email protected]>
3 changes: 3 additions & 0 deletions stock_location_children/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds a `children_ids` field on `stock.location` in order to compute
and store all the children for a `stock.location` and not only its first level
children as is the case for `child_ids`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading