diff --git a/setup/stock_free_quantity/odoo/addons/stock_free_quantity b/setup/stock_free_quantity/odoo/addons/stock_free_quantity new file mode 120000 index 000000000..360701f54 --- /dev/null +++ b/setup/stock_free_quantity/odoo/addons/stock_free_quantity @@ -0,0 +1 @@ +../../../../stock_free_quantity \ No newline at end of file diff --git a/setup/stock_free_quantity/setup.py b/setup/stock_free_quantity/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_free_quantity/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_free_quantity/README.rst b/stock_free_quantity/README.rst new file mode 100644 index 000000000..545fbfb86 --- /dev/null +++ b/stock_free_quantity/README.rst @@ -0,0 +1,73 @@ +=================== +Stock Free Quantity +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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/14.0/stock_free_quantity + :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-14-0/stock-logistics-warehouse-14-0-stock_free_quantity + :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/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add Product variant free quantity in Product form view and add the same on Product templates. + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* akretion + +Contributors +~~~~~~~~~~~~ + +* Florian da Costa + +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_free_quantity/__init__.py b/stock_free_quantity/__init__.py new file mode 100644 index 000000000..83e553ac4 --- /dev/null +++ b/stock_free_quantity/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/stock_free_quantity/__manifest__.py b/stock_free_quantity/__manifest__.py new file mode 100644 index 000000000..1321ed14d --- /dev/null +++ b/stock_free_quantity/__manifest__.py @@ -0,0 +1,17 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Stock Free Quantity", + "version": "15.0.1.0.0", + "author": "akretion,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "development_status": "Production/Stable", + "category": "Warehouse", + "depends": ["stock"], + "license": "AGPL-3", + "data": [ + "views/product_template_view.xml", + "views/product_product_view.xml", + ], + "installable": True, +} diff --git a/stock_free_quantity/i18n/stock_free_quantity.pot b/stock_free_quantity/i18n/stock_free_quantity.pot new file mode 100644 index 000000000..5ac2d4007 --- /dev/null +++ b/stock_free_quantity/i18n/stock_free_quantity.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_free_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_free_quantity +#: model_terms:ir.ui.view,arch_db:stock_free_quantity.product_normal_form_view +#: model_terms:ir.ui.view,arch_db:stock_free_quantity.view_stock_available_form +msgid "Free" +msgstr "" + +#. module: stock_free_quantity +#: model:ir.model.fields,field_description:stock_free_quantity.field_product_template__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_free_quantity +#: model:ir.model.fields,field_description:stock_free_quantity.field_product_template__free_qty +msgid "Free Quantity" +msgstr "" + +#. module: stock_free_quantity +#: model_terms:ir.ui.view,arch_db:stock_free_quantity.product_template_kanban_free_qty_view +msgid "Free:" +msgstr "" + +#. module: stock_free_quantity +#: model:ir.model.fields,field_description:stock_free_quantity.field_product_template__id +msgid "ID" +msgstr "" + +#. module: stock_free_quantity +#: model:ir.model.fields,field_description:stock_free_quantity.field_product_template____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_free_quantity +#: model:ir.model,name:stock_free_quantity.model_product_template +msgid "Product Template" +msgstr "" diff --git a/stock_free_quantity/models/__init__.py b/stock_free_quantity/models/__init__.py new file mode 100644 index 000000000..e8fa8f6bf --- /dev/null +++ b/stock_free_quantity/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/stock_free_quantity/models/product_template.py b/stock_free_quantity/models/product_template.py new file mode 100644 index 000000000..b38fffd2e --- /dev/null +++ b/stock_free_quantity/models/product_template.py @@ -0,0 +1,34 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _compute_quantities_dict(self): + prod_available = super()._compute_quantities_dict() + for template in self: + free_qty = 0 + for p in template.with_context(active_test=False).product_variant_ids: + free_qty += p.free_qty + prod_available[template.id]["free_qty"] = free_qty + return prod_available + + def _compute_quantities(self): + super()._compute_quantities() + res = self._compute_quantities_dict() + for template in self: + template.free_qty = res[template.id]["free_qty"] + return + + def _search_free_qty(self, operator, value): + return [("product_variant_ids.free_qty", operator, value)] + + free_qty = fields.Float( + "Free Quantity", + compute="_compute_quantities", + search="_search_free_qty", + compute_sudo=False, + digits="Product Unit of Measure", + ) diff --git a/stock_free_quantity/readme/CONTRIBUTORS.rst b/stock_free_quantity/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..4a0fcc100 --- /dev/null +++ b/stock_free_quantity/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florian da Costa diff --git a/stock_free_quantity/readme/DESCRIPTION.rst b/stock_free_quantity/readme/DESCRIPTION.rst new file mode 100644 index 000000000..2c34c0f59 --- /dev/null +++ b/stock_free_quantity/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add Product variant free quantity in Product form view and add the same on Product templates. diff --git a/stock_free_quantity/static/description/index.html b/stock_free_quantity/static/description/index.html new file mode 100644 index 000000000..7b2cdb11d --- /dev/null +++ b/stock_free_quantity/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Stock Free Quantity + + + +
+

Stock Free Quantity

+ + +

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

+

Add Product variant free quantity in Product form view and add the same on Product templates.

+

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

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • akretion
  • +
+
+
+

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_free_quantity/tests/__init__.py b/stock_free_quantity/tests/__init__.py new file mode 100644 index 000000000..fba51672b --- /dev/null +++ b/stock_free_quantity/tests/__init__.py @@ -0,0 +1 @@ +from . import test_template_free_qty diff --git a/stock_free_quantity/tests/test_template_free_qty.py b/stock_free_quantity/tests/test_template_free_qty.py new file mode 100644 index 000000000..79365158d --- /dev/null +++ b/stock_free_quantity/tests/test_template_free_qty.py @@ -0,0 +1,35 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.tests.common import TransactionCase + + +class TestTemplateFreeQty(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.template_with_variant = cls.env.ref( + "product.product_product_11_product_template" + ) + cls.template_with_no_variant = cls.env.ref( + "product.product_product_10_product_template" + ) + + def test_template_free_qty(self): + # template has 2 variants with 26 and 30 free qty, template should have 56 + self.assertEqual(self.template_with_variant.free_qty, 56) + self.assertEqual( + self.template_with_no_variant.free_qty, + self.template_with_no_variant.product_variant_ids.free_qty, + ) + + def test_search_template_free_qty(self): + template_with_free_qty_ids = ( + self.env["product.template"].search([("free_qty", ">", 0)]).ids + ) + self.assertIn(self.template_with_variant.id, template_with_free_qty_ids) + self.assertIn(self.template_with_no_variant.id, template_with_free_qty_ids) + template_with_no_free_qty = self.env.ref( + "product.product_product_22_product_template" + ) + self.assertNotIn(template_with_no_free_qty.id, template_with_free_qty_ids) diff --git a/stock_free_quantity/views/product_product_view.xml b/stock_free_quantity/views/product_product_view.xml new file mode 100644 index 000000000..8704ed650 --- /dev/null +++ b/stock_free_quantity/views/product_product_view.xml @@ -0,0 +1,36 @@ + + + + + product.product + + + + + + + + + diff --git a/stock_free_quantity/views/product_template_view.xml b/stock_free_quantity/views/product_template_view.xml new file mode 100644 index 000000000..0c90e0b11 --- /dev/null +++ b/stock_free_quantity/views/product_template_view.xml @@ -0,0 +1,84 @@ + + + + product.template + + + + + + + + + + product.template + + + + +
Free:
+
+
+
+ + + product.template + + + + + + + + + + product.product + + + + + + + + +