diff --git a/setup/stock_available_location_get_domain/odoo/addons/stock_available_location_get_domain b/setup/stock_available_location_get_domain/odoo/addons/stock_available_location_get_domain new file mode 120000 index 00000000..915024ea --- /dev/null +++ b/setup/stock_available_location_get_domain/odoo/addons/stock_available_location_get_domain @@ -0,0 +1 @@ +../../../../stock_available_location_get_domain \ No newline at end of file diff --git a/setup/stock_available_location_get_domain/setup.py b/setup/stock_available_location_get_domain/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/stock_available_location_get_domain/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_available_location_get_domain/README.rst b/stock_available_location_get_domain/README.rst new file mode 100644 index 00000000..471d661d --- /dev/null +++ b/stock_available_location_get_domain/README.rst @@ -0,0 +1,84 @@ +=================================== +Stock Available Location Get Domain +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:943a988f24484f4a3db1de40304f1bf42d40ce80274f9ae48c5b41fc408848f6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--availability-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-availability/tree/16.0/stock_available_location_get_domain + :alt: OCA/stock-logistics-availability +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-availability-16-0/stock-logistics-availability-16-0-stock_available_location_get_domain + :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-availability&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This is a technical helper module in order to reuse the standard +_get_domain_locations function for locations and not quants. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Call the new _get_domain_location_for_locations() function on products in order +to retrieve a domain for stock locations with the same context behavior as +for product availability. + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Denis Roussel + +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-availability `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_available_location_get_domain/__init__.py b/stock_available_location_get_domain/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/stock_available_location_get_domain/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_available_location_get_domain/__manifest__.py b/stock_available_location_get_domain/__manifest__.py new file mode 100644 index 00000000..2bf19ada --- /dev/null +++ b/stock_available_location_get_domain/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Available Location Get Domain", + "summary": """ + This is a technical helper module in order to reuse the standard + _get_domain_locations() function for locations and not quants""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-availability", + "depends": ["stock"], +} diff --git a/stock_available_location_get_domain/models/__init__.py b/stock_available_location_get_domain/models/__init__.py new file mode 100644 index 00000000..5c74c8c3 --- /dev/null +++ b/stock_available_location_get_domain/models/__init__.py @@ -0,0 +1 @@ +from . import product_product diff --git a/stock_available_location_get_domain/models/product_product.py b/stock_available_location_get_domain/models/product_product.py new file mode 100644 index 00000000..1bd1a4db --- /dev/null +++ b/stock_available_location_get_domain/models/product_product.py @@ -0,0 +1,33 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.osv import expression + + +class ProductProduct(models.Model): + + _inherit = "product.product" + + def _get_domain_location_for_locations(self): + """ + Adapt the domain computed for stock.quant for stock.location + """ + quant_domain = self._get_domain_locations()[0] + # Adapt the domain on quants by replacing location_id by "" + # Be sure to exclude potential fields that couldn't belong to stock.location + # and replace by nothing + location_domain = [] + location_fields = self.env["stock.location"].fields_get() + for element in quant_domain: + leaf = expression.is_leaf(element) + if leaf: + field = leaf.split(".")[0] + if field in location_fields and field != "location_id": + location_domain.append(element) + elif field == "location_id": + location_domain.append( + (element[0].replace("location_id.", ""), element[1], element[2]) + ) + else: + location_domain.append(element) + return location_domain diff --git a/stock_available_location_get_domain/readme/CONTRIBUTORS.rst b/stock_available_location_get_domain/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9179ee4b --- /dev/null +++ b/stock_available_location_get_domain/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Denis Roussel diff --git a/stock_available_location_get_domain/readme/DESCRIPTION.rst b/stock_available_location_get_domain/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c71b8021 --- /dev/null +++ b/stock_available_location_get_domain/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This is a technical helper module in order to reuse the standard +_get_domain_locations function for locations and not quants. diff --git a/stock_available_location_get_domain/readme/USAGE.rst b/stock_available_location_get_domain/readme/USAGE.rst new file mode 100644 index 00000000..38fd1910 --- /dev/null +++ b/stock_available_location_get_domain/readme/USAGE.rst @@ -0,0 +1,3 @@ +Call the new _get_domain_location_for_locations() function on products in order +to retrieve a domain for stock locations with the same context behavior as +for product availability. diff --git a/stock_available_location_get_domain/static/description/icon.png b/stock_available_location_get_domain/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/stock_available_location_get_domain/static/description/icon.png differ diff --git a/stock_available_location_get_domain/static/description/index.html b/stock_available_location_get_domain/static/description/index.html new file mode 100644 index 00000000..d34cf7a5 --- /dev/null +++ b/stock_available_location_get_domain/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Stock Available Location Get Domain + + + +
+

Stock Available Location Get Domain

+ + +

Beta License: AGPL-3 OCA/stock-logistics-availability Translate me on Weblate Try me on Runboat

+

This is a technical helper module in order to reuse the standard +_get_domain_locations function for locations and not quants.

+

Table of contents

+ +
+

Usage

+

Call the new _get_domain_location_for_locations() function on products in order +to retrieve a domain for stock locations with the same context behavior as +for product availability.

+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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-availability project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_available_location_get_domain/tests/__init__.py b/stock_available_location_get_domain/tests/__init__.py new file mode 100644 index 00000000..bbff51c5 --- /dev/null +++ b/stock_available_location_get_domain/tests/__init__.py @@ -0,0 +1 @@ +from . import test_location_domain diff --git a/stock_available_location_get_domain/tests/test_location_domain.py b/stock_available_location_get_domain/tests/test_location_domain.py new file mode 100644 index 00000000..e4d9a4f7 --- /dev/null +++ b/stock_available_location_get_domain/tests/test_location_domain.py @@ -0,0 +1,72 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestStockLocationDomain(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.stock_1 = cls.env["stock.location"].create( + { + "name": "Stock 1", + "location_id": cls.warehouse.lot_stock_id.id, + } + ) + + cls.stock_1_1 = cls.env["stock.location"].create( + { + "name": "Stock 1.1", + "location_id": cls.stock_1.id, + } + ) + + cls.warehouse_2 = cls.env["stock.warehouse"].create( + { + "name": "Warehouse 2", + "code": "WH2", + } + ) + + cls.stock_2 = cls.env["stock.location"].create( + { + "name": "Stock 2", + "location_id": cls.warehouse_2.lot_stock_id.id, + } + ) + + cls.stock_2_1 = cls.env["stock.location"].create( + { + "name": "Stock 2.1", + "location_id": cls.stock_2.id, + } + ) + + def test_domain(self): + locations = self.env["stock.location"].search( + self.env["product.product"]._get_domain_location_for_locations() + ) + self.assertTrue(self.stock_1.id in locations.ids) + self.assertTrue(self.stock_1_1.id in locations.ids) + + locations = self.env["stock.location"].search( + self.env["product.product"] + .with_context(location=self.stock_1_1.id) + ._get_domain_location_for_locations() + ) + + self.assertEqual(self.stock_1_1, locations) + + locations = self.env["stock.location"].search( + self.env["product.product"] + .with_context(warehouse=self.warehouse_2.id) + ._get_domain_location_for_locations() + ) + + self.assertTrue(self.stock_2.id in locations.ids) + self.assertTrue(self.stock_2_1.id in locations.ids) + + self.assertFalse(self.stock_1.id in locations.ids) + self.assertFalse(self.stock_1_1.id in locations.ids)