diff --git a/stock_helper/README.rst b/stock_helper/README.rst new file mode 100644 index 000000000..093e62e16 --- /dev/null +++ b/stock_helper/README.rst @@ -0,0 +1,78 @@ +============= +Stock Helpers +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7ae8c9003b4096ec1cd8ce5881efe5baf98ef80529f51442e1d690492eff9245 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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/17.0/stock_helper + :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-17-0/stock-logistics-warehouse-17-0-stock_helper + :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-warehouse&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add methods to be used by other modules. This is not a functional +module. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Guewen Baconnier +- Christopher Ormaza + +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_helper/__init__.py b/stock_helper/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_helper/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_helper/__manifest__.py b/stock_helper/__manifest__.py new file mode 100644 index 000000000..9f257b590 --- /dev/null +++ b/stock_helper/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020-2021 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Helpers", + "summary": "Add methods shared between various stock modules", + "version": "17.0.1.1.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Hidden", + "depends": ["stock"], + "data": [], + "installable": True, + "license": "LGPL-3", +} diff --git a/stock_helper/i18n/hr.po b/stock_helper/i18n/hr.po new file mode 100644 index 000000000..7dc9bef8c --- /dev/null +++ b/stock_helper/i18n/hr.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_helper +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-02-16 15:23+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: stock_helper +#: model:ir.model,name:stock_helper.model_stock_location +msgid "Inventory Locations" +msgstr "Skladišne lokacije" diff --git a/stock_helper/i18n/it.po b/stock_helper/i18n/it.po new file mode 100644 index 000000000..729e44558 --- /dev/null +++ b/stock_helper/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_helper +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-21 13:33+0000\n" +"Last-Translator: mymage \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_helper +#: model:ir.model,name:stock_helper.model_stock_location +msgid "Inventory Locations" +msgstr "Ubicazioni di inventario" diff --git a/stock_helper/i18n/stock_helper.pot b/stock_helper/i18n/stock_helper.pot new file mode 100644 index 000000000..071eb9894 --- /dev/null +++ b/stock_helper/i18n/stock_helper.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_helper +# +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_helper +#: model:ir.model,name:stock_helper.model_stock_location +msgid "Inventory Locations" +msgstr "" diff --git a/stock_helper/models/__init__.py b/stock_helper/models/__init__.py new file mode 100644 index 000000000..88493e35d --- /dev/null +++ b/stock_helper/models/__init__.py @@ -0,0 +1 @@ +from . import stock_location diff --git a/stock_helper/models/stock_location.py b/stock_helper/models/stock_location.py new file mode 100644 index 000000000..1a1d813a1 --- /dev/null +++ b/stock_helper/models/stock_location.py @@ -0,0 +1,38 @@ +# Copyright 2020-2021 Camptocamp SA (http://www.camptocamp.com) +# Copyright 2022-2023 Michael Tietz (MT Software) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + def is_sublocation_of(self, others, func=any): + """Return True if self is a sublocation of others (or equal) + + By default, it return True if any other is a parent or equal. + ``all`` can be passed to ``func`` to require all the other locations + to be parent or equal to be True. + """ + self.ensure_one() + # Efficient way to verify that the current location is + # below one of the other location without using SQL. + return func(self.parent_path.startswith(other.parent_path) for other in others) + + def _get_source_location_from_route(self, route, procure_method): + self.ensure_one() + route.ensure_one() + values = { + "route_ids": route, + } + current_location = self + while current_location: + rule = self.env["procurement.group"]._get_rule( + self.env["product.product"], current_location, values + ) + if not rule: + return self.browse() + if rule.procure_method == procure_method: + return rule.location_src_id + current_location = rule.location_src_id diff --git a/stock_helper/pyproject.toml b/stock_helper/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/stock_helper/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_helper/readme/CONTRIBUTORS.md b/stock_helper/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..6b260d630 --- /dev/null +++ b/stock_helper/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Guewen Baconnier \<\> +- Christopher Ormaza \<\> diff --git a/stock_helper/readme/DESCRIPTION.md b/stock_helper/readme/DESCRIPTION.md new file mode 100644 index 000000000..17c025cb6 --- /dev/null +++ b/stock_helper/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Add methods to be used by other modules. This is not a functional +module. diff --git a/stock_helper/static/description/icon.png b/stock_helper/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_helper/static/description/icon.png differ diff --git a/stock_helper/static/description/index.html b/stock_helper/static/description/index.html new file mode 100644 index 000000000..c38e80168 --- /dev/null +++ b/stock_helper/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +Stock Helpers + + + +
+

Stock Helpers

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

Add methods to be used by other modules. This is not a functional +module.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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_helper/tests/__init__.py b/stock_helper/tests/__init__.py new file mode 100644 index 000000000..be6a115be --- /dev/null +++ b/stock_helper/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_location_is_sublocation_of +from . import test_location_source_from_route diff --git a/stock_helper/tests/common.py b/stock_helper/tests/common.py new file mode 100644 index 000000000..f7515a7a1 --- /dev/null +++ b/stock_helper/tests/common.py @@ -0,0 +1,19 @@ +# Copyright 2020-2021 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo.tests import TransactionCase + + +class StockHelperCommonCase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + cls.wh = cls.env.ref("stock.warehouse0") + + cls.customer_loc = cls.env.ref("stock.stock_location_customers") + cls.supplier_loc = cls.env.ref("stock.stock_location_suppliers") + cls.stock_loc = cls.wh.lot_stock_id + cls.shelf1_loc = cls.env.ref("stock.stock_location_components") + cls.shelf2_loc = cls.env.ref("stock.stock_location_14") diff --git a/stock_helper/tests/test_location_is_sublocation_of.py b/stock_helper/tests/test_location_is_sublocation_of.py new file mode 100644 index 000000000..f88047727 --- /dev/null +++ b/stock_helper/tests/test_location_is_sublocation_of.py @@ -0,0 +1,48 @@ +# Copyright 2020-2021 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + + +from .common import StockHelperCommonCase + + +class TestStockLocationIsSublocationOf(StockHelperCommonCase): + def test_is_sublocation_of_equal(self): + self.assertTrue(self.shelf1_loc.is_sublocation_of(self.shelf1_loc)) + + def test_is_sublocation_of_equal_child_ko(self): + bin_loc = self.env["stock.location"].create( + {"name": "bin", "location_id": self.shelf1_loc.id} + ) + self.assertFalse(self.shelf1_loc.is_sublocation_of(bin_loc)) + + def test_is_sublocation_of_equal_child_sibling(self): + self.assertFalse(self.shelf1_loc.is_sublocation_of(self.shelf2_loc)) + + def test_is_sublocation_of_any_ok(self): + self.assertTrue( + self.shelf1_loc.is_sublocation_of(self.stock_loc | self.customer_loc) + ) + + def test_is_sublocation_of_any_ko(self): + self.assertFalse( + self.shelf1_loc.is_sublocation_of(self.supplier_loc | self.customer_loc) + ) + + def test_is_sublocation_of_all_ok(self): + self.assertTrue( + self.shelf1_loc.is_sublocation_of( + self.stock_loc | self.stock_loc.location_id, func=all + ) + ) + + def test_is_sublocation_of_all_ko(self): + self.assertFalse( + self.shelf1_loc.is_sublocation_of( + self.stock_loc | self.customer_loc, func=all + ) + ) + self.assertFalse( + self.shelf1_loc.is_sublocation_of( + self.supplier_loc | self.customer_loc, func=all + ) + ) diff --git a/stock_helper/tests/test_location_source_from_route.py b/stock_helper/tests/test_location_source_from_route.py new file mode 100644 index 000000000..9768b9a65 --- /dev/null +++ b/stock_helper/tests/test_location_source_from_route.py @@ -0,0 +1,40 @@ +# Copyright 2022 Michael Tietz (MT Software) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + + +from .common import StockHelperCommonCase + + +class TestStockLocationSoruceFromRoute(StockHelperCommonCase): + def test_get_source_location_from_route(self): + self.wh.delivery_steps = "pick_pack_ship" + route = self.wh.delivery_route_id + + location = self.env.ref("stock.stock_location_customers") + source_location = location._get_source_location_from_route( + route, "make_to_stock" + ) + self.assertEqual(source_location, self.wh.lot_stock_id) + + source_location = location._get_source_location_from_route( + route, "make_to_order" + ) + self.assertEqual(source_location, self.wh.wh_output_stock_loc_id) + + location = source_location + source_location = location._get_source_location_from_route( + route, "make_to_order" + ) + self.assertEqual(source_location, self.wh.wh_pack_stock_loc_id) + + location = source_location + source_location = location._get_source_location_from_route( + route, "make_to_stock" + ) + self.assertEqual(source_location, self.wh.lot_stock_id) + + location = source_location + source_location = location._get_source_location_from_route( + route, "make_to_stock" + ) + self.assertEqual(source_location, self.supplier_loc)