diff --git a/stock_available_base_exclude_location/README.rst b/stock_available_base_exclude_location/README.rst new file mode 100644 index 00000000..075d3108 --- /dev/null +++ b/stock_available_base_exclude_location/README.rst @@ -0,0 +1,103 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +===================================== +Stock Available Base Exclude Location +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e10cd857d3686fca227a280cedda4aa830c2308bd03beb11bff5cefcd8f030ac + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/stock_available_base_exclude_location + :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-19-0/stock-logistics-availability-19-0-stock_available_base_exclude_location + :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=19.0 + :alt: Try me on Runboat + +|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 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 +- Xavier Bouquiaux +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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-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_base_exclude_location/__init__.py b/stock_available_base_exclude_location/__init__.py new file mode 100644 index 00000000..0650744f --- /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 00000000..6641d634 --- /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 (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Available Base Exclude Location", + "summary": """ + Base module to exclude locations for product available quantities""", + "version": "19.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-availability", + "depends": ["stock"], +} diff --git a/stock_available_base_exclude_location/i18n/fr.po b/stock_available_base_exclude_location/i18n/fr.po new file mode 100644 index 00000000..16fe815a --- /dev/null +++ b/stock_available_base_exclude_location/i18n/fr.po @@ -0,0 +1,55 @@ +# 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 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\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" + +#. 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_domain_char +msgid "Domain to filter locations" +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 available quantities." +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_domain +#: model:ir.model.fields,help:stock_available_base_exclude_location.field_stock_exclude_location_mixin__stock_excluded_location_domain_char +msgid "" +"Fill in this with the domain you want to exclude locations for product " +"available quantities" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_product_product +msgid "Product Variant" +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_domain +msgid "Stock Excluded Location Domain" +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 Locations" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_stock_exclude_location_mixin +msgid "" +"technical base module to allow defining excluded locations on an Odoo model" +msgstr "" diff --git a/stock_available_base_exclude_location/i18n/it.po b/stock_available_base_exclude_location/i18n/it.po new file mode 100644 index 00000000..6fa507e4 --- /dev/null +++ b/stock_available_base_exclude_location/i18n/it.po @@ -0,0 +1,63 @@ +# 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 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-10 08:41+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_available_base_exclude_location +#: model:ir.model.fields,field_description:stock_available_base_exclude_location.field_stock_exclude_location_mixin__stock_excluded_location_domain_char +msgid "Domain to filter locations" +msgstr "Dominio per filtrare le ubicazioni" + +#. 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 "" +"Compilare questo campo per escludere ubicazioni dalle quantità disponibili " +"del prodotto." + +#. module: stock_available_base_exclude_location +#: model:ir.model.fields,help:stock_available_base_exclude_location.field_stock_exclude_location_mixin__stock_excluded_location_domain +#: model:ir.model.fields,help:stock_available_base_exclude_location.field_stock_exclude_location_mixin__stock_excluded_location_domain_char +msgid "" +"Fill in this with the domain you want to exclude locations for product " +"available quantities" +msgstr "" +"Compilare questo campo con il dominio che si vuole utilizzare per escludere " +"le ubicazioni per le quantià prodotto disponibili" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. 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_domain +msgid "Stock Excluded Location Domain" +msgstr "Dominio ubicazione esclusa dalla giacenza" + +#. 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 Locations" +msgstr "Ubicazioni escluse dalla giacenza" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_stock_exclude_location_mixin +msgid "" +"technical base module to allow defining excluded locations on an Odoo model" +msgstr "" +"modulo tecnico base per consentire la definizione di ubicazioni escluse su " +"un modello Odoo" 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 00000000..b2593837 --- /dev/null +++ b/stock_available_base_exclude_location/i18n/stock_available_base_exclude_location.pot @@ -0,0 +1,54 @@ +# 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 18.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__stock_excluded_location_domain_char +msgid "Domain to filter locations" +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 available quantities." +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_domain +#: model:ir.model.fields,help:stock_available_base_exclude_location.field_stock_exclude_location_mixin__stock_excluded_location_domain_char +msgid "" +"Fill in this with the domain you want to exclude locations for product " +"available quantities" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_product_product +msgid "Product Variant" +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_domain +msgid "Stock Excluded Location Domain" +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 Locations" +msgstr "" + +#. module: stock_available_base_exclude_location +#: model:ir.model,name:stock_available_base_exclude_location.model_stock_exclude_location_mixin +msgid "" +"technical base module to allow defining excluded locations on an Odoo model" +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 00000000..53274ab9 --- /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 00000000..e8623a84 --- /dev/null +++ b/stock_available_base_exclude_location/models/product_product.py @@ -0,0 +1,68 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models +from odoo.fields import Domain + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def _get_domain_locations_new(self, location_ids): + """ + 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, + ) + excluded_location_ids = self.env.context.get("excluded_location_ids", []) + excluded_location_domain = self.env.context.get("excluded_location_domain", []) + domain_excluded_quant_loc = [] + domain_excluded_move_in_loc = [] + domain_excluded_move_out_loc = [] + if excluded_location_ids: + domain_excluded_quant_loc = list( + Domain([("location_id", "not in", excluded_location_ids.ids)]) + & Domain(domain_excluded_quant_loc) + ) + domain_excluded_move_in_loc = list( + Domain([("location_id", "not in", excluded_location_ids.ids)]) + & Domain(domain_excluded_move_in_loc) + ) + domain_excluded_move_out_loc = list( + Domain([("location_id", "not in", excluded_location_ids.ids)]) + & Domain(domain_excluded_move_out_loc) + ) + if excluded_location_domain: + domain_excluded_quant_loc = list( + Domain(excluded_location_domain) & Domain(domain_excluded_quant_loc) + ) + domain_excluded_move_in_loc = list( + Domain(excluded_location_domain) & Domain(domain_excluded_move_in_loc) + ) + domain_excluded_move_out_loc = list( + Domain(excluded_location_domain) & Domain(domain_excluded_move_out_loc) + ) + domain_quant_loc = ( + list(Domain(domain_excluded_quant_loc) & Domain(domain_quant_loc)) + if domain_excluded_quant_loc + else domain_quant_loc + ) + domain_move_in_loc = ( + list(Domain(domain_excluded_move_in_loc) & Domain(domain_move_in_loc)) + if domain_excluded_move_in_loc + else domain_move_in_loc + ) + domain_move_out_loc = ( + list(Domain(domain_excluded_move_out_loc) & Domain(domain_move_out_loc)) + if domain_excluded_move_in_loc + else domain_move_out_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 00000000..80747da8 --- /dev/null +++ b/stock_available_base_exclude_location/models/stock_exclude_location_mixin.py @@ -0,0 +1,36 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.tools.safe_eval import safe_eval + + +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", + string="Stock Excluded Locations", + help="Fill in this field to exclude locations for product available " + "quantities.", + ) + stock_excluded_location_domain = fields.Binary( + compute="_compute_stock_excluded_location_domain", + help="Fill in this with the domain you want to exclude locations for " + "product available quantities", + ) + stock_excluded_location_domain_char = fields.Char( + default="[]", + string="Domain to filter locations", + help="Fill in this with the domain you want to exclude locations for " + "product available quantities", + ) + + @api.depends("stock_excluded_location_domain_char") + def _compute_stock_excluded_location_domain(self): + for record in self: + record.stock_excluded_location_domain = safe_eval( + record.stock_excluded_location_domain_char + ) diff --git a/stock_available_base_exclude_location/pyproject.toml b/stock_available_base_exclude_location/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/stock_available_base_exclude_location/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_available_base_exclude_location/readme/CONTRIBUTORS.md b/stock_available_base_exclude_location/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..09e062e7 --- /dev/null +++ b/stock_available_base_exclude_location/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Denis Roussel \ +- Xavier Bouquiaux \ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/stock_available_base_exclude_location/readme/DESCRIPTION.md b/stock_available_base_exclude_location/readme/DESCRIPTION.md new file mode 100644 index 00000000..1a081a7c --- /dev/null +++ b/stock_available_base_exclude_location/readme/DESCRIPTION.md @@ -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.md b/stock_available_base_exclude_location/readme/USAGE.md new file mode 100644 index 00000000..52979214 --- /dev/null +++ b/stock_available_base_exclude_location/readme/USAGE.md @@ -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 00000000..3a0328b5 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 00000000..41ad0371 --- /dev/null +++ b/stock_available_base_exclude_location/static/description/index.html @@ -0,0 +1,446 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Stock Available Base Exclude Location

+ +

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

+

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

+

Current maintainer:

+

rousseldenis

+

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_base_exclude_location/tests/__init__.py b/stock_available_base_exclude_location/tests/__init__.py new file mode 100644 index 00000000..7e9fc5d7 --- /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 00000000..40cc1ae2 --- /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 TestExcludeLocationOwner(models.Model): + _name = "test.exclude.location.owner" + _inherit = ["stock.exclude.location.mixin"] + _description = "Test model for 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 00000000..926ae68a --- /dev/null +++ b/stock_available_base_exclude_location/tests/test_stock_exclude_location.py @@ -0,0 +1,126 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.orm.model_classes import add_to_registry +from odoo.tests import common + +from odoo.addons.stock.models.stock_location import StockLocation as Location +from odoo.addons.stock.models.stock_move import StockMove + + +class TestExcludeLocation(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + from .common import TestExcludeLocationOwner + + add_to_registry(cls.registry, TestExcludeLocationOwner) + cls.registry._setup_models__(cls.env.cr, [TestExcludeLocationOwner._name]) + cls.registry.init_models( + cls.env.cr, + [TestExcludeLocationOwner._name], + {"models_to_check": True}, + ) + cls.addClassCleanup(cls.registry.__delitem__, TestExcludeLocationOwner._name) + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + 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.product = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "consu", + "is_storable": True, + } + ) + cls.fake = cls.env[TestExcludeLocationOwner._name].create({}) + + @classmethod + def _create_stock_move( + cls, quantity: float, location: Location, location_dest: Location + ) -> StockMove: + move = cls.env["stock.move"].create( + { + "location_id": location.id, + "location_dest_id": location_dest.id, + "product_id": cls.product.id, + "product_uom_qty": quantity, + "product_uom": cls.product.uom_id.id, + } + ) + move._action_confirm() + return move + + 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, + } + )._apply_inventory() + + 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_recordset() + qty = self.product.qty_available + self.assertEqual(75.0, qty) + + def test_exclude_location_domain(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_domain_char = ( + "[('location_id', 'not in', " + str(self.sub_location_1.ids) + ")]" + ) + qty = self.product.with_context( + excluded_location_domain=self.fake.stock_excluded_location_domain + ).qty_available + self.assertEqual(50.0, qty) + self.product.invalidate_recordset() + qty = self.product.qty_available + self.assertEqual(75.0, qty) + + def test_exclude_location_domain_in(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 Supplier + 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._create_stock_move( + 30.0, self.env.ref("stock.stock_location_suppliers"), self.sub_location_1 + ) + self.product.invalidate_recordset() + qty = self.product.with_context( + excluded_location_domain=self.fake.stock_excluded_location_domain + ).virtual_available + self.assertEqual(105.0, qty) + self.fake.stock_excluded_location_domain_char = ( + "[('location_id.usage', '!=', 'supplier')]" + ) + self.product.invalidate_recordset() + qty = self.product.with_context( + excluded_location_domain=self.fake.stock_excluded_location_domain + ).virtual_available + self.assertEqual(75.0, qty)