diff --git a/setup/stock_available_base_exclude_location/odoo/addons/stock_available_base_exclude_location b/setup/stock_available_base_exclude_location/odoo/addons/stock_available_base_exclude_location new file mode 120000 index 000000000..8fd8343fe --- /dev/null +++ b/setup/stock_available_base_exclude_location/odoo/addons/stock_available_base_exclude_location @@ -0,0 +1 @@ +../../../../stock_available_base_exclude_location \ No newline at end of file diff --git a/setup/stock_available_base_exclude_location/setup.py b/setup/stock_available_base_exclude_location/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_available_base_exclude_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_available_base_exclude_location/README.rst b/stock_available_base_exclude_location/README.rst new file mode 100644 index 000000000..f2d1df552 --- /dev/null +++ b/stock_available_base_exclude_location/README.rst @@ -0,0 +1,92 @@ +===================================== +Stock Available Base Exclude Location +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/10.0/stock_available_base_exclude_location + :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-10-0/stock-logistics-warehouse-10-0-stock_available_base_exclude_location + :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/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is a technical base module to allow defining excluded locations +on an Odoo model. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In new module, inherit from "stock.exclude.location.mixin" model on +the wanted model. + +Then, when querying for product availability, add to context the key +"excluded_location_ids" with your model "stock_excluded_location_ids" +property. + +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 +~~~~~~~ + +* 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. + +.. |maintainer-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +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_available_base_exclude_location/__init__.py b/stock_available_base_exclude_location/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_available_base_exclude_location/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_available_base_exclude_location/__manifest__.py b/stock_available_base_exclude_location/__manifest__.py new file mode 100644 index 000000000..cea24b301 --- /dev/null +++ b/stock_available_base_exclude_location/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Available Base Exclude Location", + "summary": """ + Base module to exclude locations for product available quantities""", + "version": "14.0.1.0.0", + "category": "Warehouse", + "maintainers": ["rousseldenis"], + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": ["stock"], +} diff --git a/stock_available_base_exclude_location/i18n/stock_available_base_exclude_location.pot b/stock_available_base_exclude_location/i18n/stock_available_base_exclude_location.pot new file mode 100644 index 000000000..79b349705 --- /dev/null +++ b/stock_available_base_exclude_location/i18n/stock_available_base_exclude_location.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_available_base_exclude_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.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_available_base_exclude_location +#: model:ir.model.fields,field_description:stock_available_base_exclude_location.field_stock_exclude_location_mixin_display_name +msgid "Display Name" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model.fields,help:stock_available_base_exclude_location.field_stock_exclude_location_mixin_stock_excluded_location_ids +msgid "Fill in this field to exclude locations for product availablequantities." +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model.fields,field_description:stock_available_base_exclude_location.field_stock_exclude_location_mixin_id +msgid "ID" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model.fields,field_description:stock_available_base_exclude_location.field_stock_exclude_location_mixin___last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_product_product +msgid "Product" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model.fields,field_description:stock_available_base_exclude_location.field_stock_exclude_location_mixin_stock_excluded_location_ids +msgid "Stock excluded location ids" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_stock_exclude_location_mixin +msgid "stock.exclude.location.mixin" +msgstr "" + diff --git a/stock_available_base_exclude_location/models/__init__.py b/stock_available_base_exclude_location/models/__init__.py new file mode 100644 index 000000000..53274ab95 --- /dev/null +++ b/stock_available_base_exclude_location/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_product +from . import stock_exclude_location_mixin diff --git a/stock_available_base_exclude_location/models/product_product.py b/stock_available_base_exclude_location/models/product_product.py new file mode 100644 index 000000000..296d3d602 --- /dev/null +++ b/stock_available_base_exclude_location/models/product_product.py @@ -0,0 +1,56 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.osv import expression + + +class ProductProduct(models.Model): + + _inherit = "product.product" + + def _get_domain_locations_new( + self, location_ids, company_id=False, compute_child=True + ): + """ + This is used to exclude locations if needed + :param location_ids: + :param company_id: + :param compute_child: + :return: + """ + ( + domain_quant_loc, + domain_move_in_loc, + domain_move_out_loc, + ) = super()._get_domain_locations_new( + location_ids=location_ids, + company_id=company_id, + compute_child=compute_child, + ) + excluded_location_ids = self.env.context.get("excluded_location_ids") + if excluded_location_ids: + domain_quant_loc = expression.AND( + [ + [("location_id", "not in", excluded_location_ids.ids)], + domain_quant_loc, + ] + ) + domain_move_in_loc = expression.AND( + [ + [ + ( + "location_dest_id", + "not in", + excluded_location_ids.ids, + ) + ], + domain_quant_loc, + ] + ) + domain_move_out_loc = expression.AND( + [ + [("location_id", "not in", excluded_location_ids.ids)], + domain_quant_loc, + ] + ) + return domain_quant_loc, domain_move_in_loc, domain_move_out_loc diff --git a/stock_available_base_exclude_location/models/stock_exclude_location_mixin.py b/stock_available_base_exclude_location/models/stock_exclude_location_mixin.py new file mode 100644 index 000000000..e6877a8a4 --- /dev/null +++ b/stock_available_base_exclude_location/models/stock_exclude_location_mixin.py @@ -0,0 +1,18 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockExcludeLocationMixin(models.AbstractModel): + + _name = "stock.exclude.location.mixin" + _description = ( + "technical base module to allow defining excluded locations on an Odoo model" + ) + + stock_excluded_location_ids = fields.Many2many( + comodel_name="stock.location", + help="Fill in this field to exclude locations for product available" + "quantities.", + ) diff --git a/stock_available_base_exclude_location/readme/CONTRIBUTORS.rst b/stock_available_base_exclude_location/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2cb5bc6f5 --- /dev/null +++ b/stock_available_base_exclude_location/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Denis Roussel +* Xavier Bouquiaux diff --git a/stock_available_base_exclude_location/readme/DESCRIPTION.rst b/stock_available_base_exclude_location/readme/DESCRIPTION.rst new file mode 100644 index 000000000..9fc10b0ca --- /dev/null +++ b/stock_available_base_exclude_location/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module is a technical base module to allow defining excluded locations +on an Odoo model. diff --git a/stock_available_base_exclude_location/readme/USAGE.rst b/stock_available_base_exclude_location/readme/USAGE.rst new file mode 100644 index 000000000..0fb2bad63 --- /dev/null +++ b/stock_available_base_exclude_location/readme/USAGE.rst @@ -0,0 +1,6 @@ +In new module, inherit from "stock.exclude.location.mixin" model on +the wanted model. + +Then, when querying for product availability, add to context the key +"excluded_location_ids" with your model "stock_excluded_location_ids" +property. diff --git a/stock_available_base_exclude_location/static/description/icon.png b/stock_available_base_exclude_location/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_available_base_exclude_location/static/description/icon.png differ diff --git a/stock_available_base_exclude_location/static/description/index.html b/stock_available_base_exclude_location/static/description/index.html new file mode 100644 index 000000000..db2967337 --- /dev/null +++ b/stock_available_base_exclude_location/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +Stock Available Base Exclude Location + + + +
+

Stock Available Base Exclude Location

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module is a technical base module to allow defining excluded locations +on an Odoo model.

+

Table of contents

+ +
+

Usage

+

In new module, inherit from “stock.exclude.location.mixin” model on +the wanted model.

+

Then, when querying for product availability, add to context the key +“excluded_location_ids” with your model “stock_excluded_location_ids” +property.

+
+
+

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

+
    +
  • 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.

+

Current maintainer:

+

rousseldenis

+

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_available_base_exclude_location/tests/__init__.py b/stock_available_base_exclude_location/tests/__init__.py new file mode 100644 index 000000000..7e9fc5d74 --- /dev/null +++ b/stock_available_base_exclude_location/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_exclude_location diff --git a/stock_available_base_exclude_location/tests/common.py b/stock_available_base_exclude_location/tests/common.py new file mode 100644 index 000000000..566a2ae87 --- /dev/null +++ b/stock_available_base_exclude_location/tests/common.py @@ -0,0 +1,9 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class ResPartner(models.Model): + + _name = "res.partner" + _inherit = ["res.partner", "stock.exclude.location.mixin"] diff --git a/stock_available_base_exclude_location/tests/test_stock_exclude_location.py b/stock_available_base_exclude_location/tests/test_stock_exclude_location.py new file mode 100644 index 000000000..0f441bae5 --- /dev/null +++ b/stock_available_base_exclude_location/tests/test_stock_exclude_location.py @@ -0,0 +1,59 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo_test_helper import FakeModelLoader + +from odoo.tests import SavepointCase + + +class TestExcludeLocation(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestExcludeLocation, cls).setUpClass() + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .common import ResPartner + + cls.loader.update_registry((ResPartner,)) + + cls.fake = cls.env["res.partner"].create({"name": "name"}) + cls.location_shop = cls.env.ref("stock.stock_location_stock") + vals = {"location_id": cls.location_shop.id, "name": "Sub Location 1"} + cls.sub_location_1 = cls.env["stock.location"].create(vals) + cls.sub_location_1._parent_store_compute() + cls.product = cls.env.ref("product.product_product_4") + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + super(TestExcludeLocation, cls).tearDownClass() + + def _add_stock_to_product(self, product, location, qty): + """ + Set the stock quantity of the product + :param product: product.product recordset + :param qty: float + """ + self.env["stock.quant"].with_context(inventory_mode=True).create( + { + "product_id": product.id, + "location_id": location.id, + "inventory_quantity": qty, + } + ) + + def test_exclude_location(self): + # Add different levels of stock for product as : + # Shop 0: 50.0 + # Sub Level (Shop 0 / Sub Location 1): 25.0 + # Query product stock availability normally and with excluded + # location as Sub Location 1 + self._add_stock_to_product(self.product, self.location_shop, 50.0) + self._add_stock_to_product(self.product, self.sub_location_1, 25.0) + self.fake.stock_excluded_location_ids = self.sub_location_1 + qty = self.product.with_context( + excluded_location_ids=self.fake.stock_excluded_location_ids + ).qty_available + self.assertEqual(50.0, qty) + self.product.invalidate_cache() + qty = self.product.qty_available + self.assertEqual(75.0, qty) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..66bc2cbae --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo_test_helper