diff --git a/setup/stock_location_warehouse/odoo/addons/stock_location_warehouse b/setup/stock_location_warehouse/odoo/addons/stock_location_warehouse new file mode 120000 index 000000000..ce3d1ae75 --- /dev/null +++ b/setup/stock_location_warehouse/odoo/addons/stock_location_warehouse @@ -0,0 +1 @@ +../../../../stock_location_warehouse \ No newline at end of file diff --git a/setup/stock_location_warehouse/setup.py b/setup/stock_location_warehouse/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_location_warehouse/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_location_warehouse/README.rst b/stock_location_warehouse/README.rst new file mode 100644 index 000000000..215b194f9 --- /dev/null +++ b/stock_location_warehouse/README.rst @@ -0,0 +1,92 @@ +========================= +Stock Location Warehouse +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_available + :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_available + :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 the associated warehouse to every location. If we have a tree of locations and sublocations, this module will update the associated warehouse every time we modify a location parent. +If a location changes its father location, it will change its associated warehouse and all its childs too. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To use the module, our instance must be configured first: +We have to go to configuration > settings and check the box in the warehouse section called "storage locations". + +Usage +===== + +The usage of this module is automatic but here's an explanation to force its behavior. +Go to Configuration>Locations and select a location that at least has one child. Edit the location's "Parent Location" to a different one and save the changes. Once the changes are saved, "Associated Warehouse" will be updated with a new warehouse. After this, go to any of its children and check the info: if things go well, "Associated Warehouse" will have changed too. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow `_: + + * Joan Mateu + + * Bernat Puig + + * Álvaro Trius + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_location_warehouse/__init__.py b/stock_location_warehouse/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_location_warehouse/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_location_warehouse/__manifest__.py b/stock_location_warehouse/__manifest__.py new file mode 100644 index 000000000..d9c9bc757 --- /dev/null +++ b/stock_location_warehouse/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Location Warehouse", + "version": "14.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "summary": "Warehouse associated with a location", + "category": "Stock Management", + "depends": ["stock"], + "data": ["views/stock_location.xml"], + "installable": True, + "development_status": "Alpha", + "license": "LGPL-3", +} diff --git a/stock_location_warehouse/models/__init__.py b/stock_location_warehouse/models/__init__.py new file mode 100644 index 000000000..88493e35d --- /dev/null +++ b/stock_location_warehouse/models/__init__.py @@ -0,0 +1 @@ +from . import stock_location diff --git a/stock_location_warehouse/models/stock_location.py b/stock_location_warehouse/models/stock_location.py new file mode 100644 index 000000000..d8065c20a --- /dev/null +++ b/stock_location_warehouse/models/stock_location.py @@ -0,0 +1,33 @@ +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from collections import OrderedDict + +from odoo import api, fields, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + warehouse_view_ids = fields.One2many( + "stock.warehouse", "view_location_id", readonly=True + ) + warehouse_id = fields.Many2one( + comodel_name="stock.warehouse", compute="_compute_warehouse_id", store=True + ) + + @api.depends("warehouse_view_ids", "parent_path") + def _compute_warehouse_id(self): + self.invalidate_cache(["parent_path", "warehouse_view_ids"]) + warehouses = ( + self.env["stock.warehouse"].with_context(active_test=False).search([]) + ) + view_by_wh = OrderedDict((wh.view_location_id.id, wh.id) for wh in warehouses) + for loc in self: + if not loc.parent_path: + continue + path = [int(loc_id) for loc_id in loc.parent_path.split("/")[:-1]] + for view_location_id in view_by_wh: + if len(path) > 1 and view_location_id == path[1]: + loc.warehouse_id = view_by_wh[view_location_id] + break diff --git a/stock_location_warehouse/readme/CONFIGURE.rst b/stock_location_warehouse/readme/CONFIGURE.rst new file mode 100644 index 000000000..3fd53e601 --- /dev/null +++ b/stock_location_warehouse/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +To use the module, our instance must be configured first: +We have to go to configuration > settings and check the box in the warehouse section called "storage locations". diff --git a/stock_location_warehouse/readme/CONTRIBUTORS.rst b/stock_location_warehouse/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..840b85f05 --- /dev/null +++ b/stock_location_warehouse/readme/CONTRIBUTORS.rst @@ -0,0 +1,7 @@ +* `ForgeFlow `_: + + * Joan Mateu + + * Bernat Puig + + * Álvaro Trius diff --git a/stock_location_warehouse/readme/DESCRIPTION.rst b/stock_location_warehouse/readme/DESCRIPTION.rst new file mode 100644 index 000000000..db696216a --- /dev/null +++ b/stock_location_warehouse/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds the associated warehouse to every location. If we have a tree of locations and sublocations, this module will update the associated warehouse every time we modify a location parent. +If a location changes its father location, it will change its associated warehouse and all its childs too. diff --git a/stock_location_warehouse/readme/USAGE.rst b/stock_location_warehouse/readme/USAGE.rst new file mode 100644 index 000000000..95f440f50 --- /dev/null +++ b/stock_location_warehouse/readme/USAGE.rst @@ -0,0 +1,2 @@ +The usage of this module is automatic but here's an explanation to force its behavior. +Go to Configuration>Locations and select a location that at least has one child. Edit the location's "Parent Location" to a different one and save the changes. Once the changes are saved, "Associated Warehouse" will be updated with a new warehouse. After this, go to any of its children and check the info: if things go well, "Associated Warehouse" will have changed too. diff --git a/stock_location_warehouse/tests/__init__.py b/stock_location_warehouse/tests/__init__.py new file mode 100644 index 000000000..1f2eeeab1 --- /dev/null +++ b/stock_location_warehouse/tests/__init__.py @@ -0,0 +1 @@ +from . import test_location_warehouse diff --git a/stock_location_warehouse/tests/test_location_warehouse.py b/stock_location_warehouse/tests/test_location_warehouse.py new file mode 100644 index 000000000..77ea62ea6 --- /dev/null +++ b/stock_location_warehouse/tests/test_location_warehouse.py @@ -0,0 +1,42 @@ +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo.tests.common import TransactionCase + + +class TestLocationWarehouse(TransactionCase): + def setUp(self, *args, **kwargs): + super(TestLocationWarehouse, self).setUp(*args, **kwargs) + self.wh_sf = self.env.ref("stock.warehouse0") + self.loc_sf = self.wh_sf.lot_stock_id + self.wh2 = self.env["stock.warehouse"].create( + { + "name": "WH 2", + "code": "WH3", + "company_id": self.wh_sf.company_id.id, + "partner_id": self.wh_sf.partner_id.id, + "reception_steps": "one_step", + } + ) + self.loc_wh2 = self.wh2.lot_stock_id + self.location1 = self.env["stock.location"].create( + {"name": "sunblock_1", "location_id": self.loc_sf.id} + ) + self.location2 = self.env["stock.location"].create( + {"name": "sunblock_2", "location_id": self.location1.id} + ) + self.location3 = self.env["stock.location"].create( + {"name": "sunblock_3", "location_id": self.location2.id} + ) + + def test_main_location(self): + self.assertEqual(self.loc_sf.warehouse_id, self.wh_sf) + + def test_compute_location(self): + self.location1.location_id = self.loc_wh2 + self.assertEqual(self.location1.warehouse_id, self.wh2) + + def test_compute_location_childs(self): + self.location1.location_id = self.loc_wh2 + self.assertEqual(self.location2.warehouse_id, self.wh2) + self.assertEqual(self.location3.warehouse_id, self.wh2) diff --git a/stock_location_warehouse/views/stock_location.xml b/stock_location_warehouse/views/stock_location.xml new file mode 100644 index 000000000..9dd559875 --- /dev/null +++ b/stock_location_warehouse/views/stock_location.xml @@ -0,0 +1,13 @@ + + + + stock.location.inherit + stock.location + + + + + + + +