diff --git a/setup/stock_lot_filter_available/odoo/addons/stock_lot_filter_available b/setup/stock_lot_filter_available/odoo/addons/stock_lot_filter_available new file mode 120000 index 000000000000..bff6f8e2446d --- /dev/null +++ b/setup/stock_lot_filter_available/odoo/addons/stock_lot_filter_available @@ -0,0 +1 @@ +../../../../stock_lot_filter_available \ No newline at end of file diff --git a/setup/stock_lot_filter_available/setup.py b/setup/stock_lot_filter_available/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_lot_filter_available/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_lot_filter_available/README.rst b/stock_lot_filter_available/README.rst new file mode 100644 index 000000000000..2868ab080d53 --- /dev/null +++ b/stock_lot_filter_available/README.rst @@ -0,0 +1,93 @@ +========================== +Stock Lot Filter Available +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/13.0/stock_lot_filter_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-13-0/stock-logistics-warehouse-13-0-stock_lot_filter_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/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows us to filter lots by available on our stock. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + + #. Go to Inventory > Master Data > Lots/Serial Numbers. + #. Press Filters > On hand. + +Now you will see just the lots with stock. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Carlos Roca + +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-CarlosRoca13| image:: https://github.com/CarlosRoca13.png?size=40px + :target: https://github.com/CarlosRoca13 + :alt: CarlosRoca13 + +Current `maintainer `__: + +|maintainer-CarlosRoca13| + +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_lot_filter_available/__init__.py b/stock_lot_filter_available/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_lot_filter_available/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_lot_filter_available/__manifest__.py b/stock_lot_filter_available/__manifest__.py new file mode 100644 index 000000000000..62b3c49bb8b9 --- /dev/null +++ b/stock_lot_filter_available/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +{ + "name": "Stock Lot Filter Available", + "summary": "Allow to filter lots by available on stock", + "version": "15.0.1.0.0", + "category": "Warehouse", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["stock"], + "data": ["views/stock_production_lot_views.xml"], + "website": "https://github.com/OCA/stock-logistics-warehouse", + "installable": True, + "maintainers": ["CarlosRoca13"], +} diff --git a/stock_lot_filter_available/i18n/es.po b/stock_lot_filter_available/i18n/es.po new file mode 100644 index 000000000000..6718e32d925d --- /dev/null +++ b/stock_lot_filter_available/i18n/es.po @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_lot_available +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-05-07 06:58+0000\n" +"PO-Revision-Date: 2021-05-07 09:00+0200\n" +"Last-Translator: Carlos \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: stock_lot_filter_available +#: model:ir.model,name:stock_lot_filter_available.model_stock_production_lot +msgid "Lot/Serial" +msgstr "Lote/Número de serie" + +#. module: stock_lot_filter_available +#: model_terms:ir.ui.view,arch_db:stock_lot_filter_available.search_product_lot_filter +msgid "On hand" +msgstr "A mano" + +#. module: stock_lot_filter_available +#: model:ir.model.fields,field_description:stock_lot_filter_available.field_stock_production_lot__product_qty +msgid "Quantity" +msgstr "Cantidad" + +#. module: stock_lot_filter_available +#: code:addons/stock_lot_filter_available/models/stock_production_lot.py:0 +#, python-format +msgid "Unsupported search" +msgstr "Búsqueda no soportada" diff --git a/stock_lot_filter_available/i18n/stock_lot_filter_available.pot b/stock_lot_filter_available/i18n/stock_lot_filter_available.pot new file mode 100644 index 000000000000..e517a7f99ab1 --- /dev/null +++ b/stock_lot_filter_available/i18n/stock_lot_filter_available.pot @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_lot_filter_available +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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_lot_filter_available +#: model:ir.model,name:stock_lot_filter_available.model_stock_production_lot +msgid "Lot/Serial" +msgstr "" + +#. module: stock_lot_filter_available +#: model_terms:ir.ui.view,arch_db:stock_lot_filter_available.search_product_lot_filter +msgid "On hand" +msgstr "" + +#. module: stock_lot_filter_available +#: model:ir.model.fields,field_description:stock_lot_filter_available.field_stock_production_lot__product_qty +msgid "Quantity" +msgstr "" + +#. module: stock_lot_filter_available +#: code:addons/stock_lot_filter_available/models/stock_production_lot.py:0 +#, python-format +msgid "Unsupported search" +msgstr "" diff --git a/stock_lot_filter_available/models/__init__.py b/stock_lot_filter_available/models/__init__.py new file mode 100644 index 000000000000..dd885b7bed84 --- /dev/null +++ b/stock_lot_filter_available/models/__init__.py @@ -0,0 +1 @@ +from . import stock_production_lot diff --git a/stock_lot_filter_available/models/stock_production_lot.py b/stock_lot_filter_available/models/stock_production_lot.py new file mode 100644 index 000000000000..873fe974e6ab --- /dev/null +++ b/stock_lot_filter_available/models/stock_production_lot.py @@ -0,0 +1,46 @@ +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import operator as operator_lib + +from odoo import _, fields, models + + +class StockProductionLot(models.Model): + _inherit = "stock.production.lot" + + product_qty = fields.Float(search="_search_product_qty") + + def _search_product_qty(self, operator, value): + operator_mapping = { + ">": operator_lib.gt, + ">=": operator_lib.ge, + "<": operator_lib.lt, + "<=": operator_lib.le, + "=": operator_lib.eq, + "!=": operator_lib.ne, + } + if operator not in operator_mapping: + raise ValueError(_("Unsupported search")) + ids = [] + domain = [ + ("location_id.usage", "in", ["internal", "transit"]), + ("lot_id", "!=", False), + ] + groups = self.env["stock.quant"].read_group( + domain, ["lot_id", "quantity"], ["lot_id"] + ) + involved_lot_ids = [group["lot_id"][0] for group in groups] + if ( + (operator == "=" and value == 0) + or (operator == "<" and value > 0) + or (operator == "<=" and value >= 0) + ): + ids.extend( + self.env["stock.production.lot"] + .search([("id", "not in", involved_lot_ids)]) + .ids + ) + for group in groups: + if operator_mapping[operator](group["quantity"], value): + ids.append(group["lot_id"][0]) + return [("id", "in", ids)] diff --git a/stock_lot_filter_available/readme/CONTRIBUTORS.rst b/stock_lot_filter_available/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..3b98bebb6563 --- /dev/null +++ b/stock_lot_filter_available/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Carlos Roca diff --git a/stock_lot_filter_available/readme/DESCRIPTION.rst b/stock_lot_filter_available/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3411dac6641f --- /dev/null +++ b/stock_lot_filter_available/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows us to filter lots by available on our stock. diff --git a/stock_lot_filter_available/readme/USAGE.rst b/stock_lot_filter_available/readme/USAGE.rst new file mode 100644 index 000000000000..2d8a940610ea --- /dev/null +++ b/stock_lot_filter_available/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module: + + #. Go to Inventory > Products > Lots/Serial Numbers. + #. Press Filters > On hand. + +Now you will see just the lots with stock. diff --git a/stock_lot_filter_available/static/description/icon.png b/stock_lot_filter_available/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_lot_filter_available/static/description/icon.png differ diff --git a/stock_lot_filter_available/static/description/index.html b/stock_lot_filter_available/static/description/index.html new file mode 100644 index 000000000000..1519c277d4a7 --- /dev/null +++ b/stock_lot_filter_available/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Stock Lot Filter Available + + + +
+

Stock Lot Filter Available

+ + +

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

+

This module allows us to filter lots by available on our stock.

+

Table of contents

+ +
+

Usage

+

To use this module:

+
+
    +
  1. Go to Inventory > Master Data > Lots/Serial Numbers.
  2. +
  3. Press Filters > On hand.
  4. +
+
+

Now you will see just the lots with stock.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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:

+

CarlosRoca13

+

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_lot_filter_available/tests/__init__.py b/stock_lot_filter_available/tests/__init__.py new file mode 100644 index 000000000000..a1988e0737c5 --- /dev/null +++ b/stock_lot_filter_available/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_lot_filter_available diff --git a/stock_lot_filter_available/tests/test_stock_lot_filter_available.py b/stock_lot_filter_available/tests/test_stock_lot_filter_available.py new file mode 100644 index 000000000000..ad160bb80427 --- /dev/null +++ b/stock_lot_filter_available/tests/test_stock_lot_filter_available.py @@ -0,0 +1,36 @@ +# Copyright 2021 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestStockLotFilterAvailable(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.StockProductionLot = cls.env["stock.production.lot"] + cls.company = cls.env.ref("base.main_company") + cls.loc = cls.env.ref("stock.stock_location_stock") + cls.product = cls.env["product.product"].create( + {"name": "Test product", "detailed_type": "product", "tracking": "lot"} + ) + cls.lot = cls.StockProductionLot.create( + { + "name": "TT-LOT", + "product_id": cls.product.id, + "company_id": cls.company.id, + } + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, cls.loc, 100, lot_id=cls.lot + ) + + def test_bad_operator(self): + with self.assertRaises(ValueError): + self.StockProductionLot._search_product_qty("in", [10, 15]) + + def test_good_operator(self): + domain = self.StockProductionLot._search_product_qty(">", 0) + self.assertTrue(self.lot.id in domain[0][2]) + domain = self.StockProductionLot._search_product_qty(">", 2) + self.assertTrue(self.lot.id in domain[0][2]) diff --git a/stock_lot_filter_available/views/stock_production_lot_views.xml b/stock_lot_filter_available/views/stock_production_lot_views.xml new file mode 100644 index 000000000000..bd0adbaf748f --- /dev/null +++ b/stock_lot_filter_available/views/stock_production_lot_views.xml @@ -0,0 +1,19 @@ + + + + + Production Lots Filter + stock.production.lot + + + + + + + +