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/__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..b78e66fb0 --- /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": "14.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/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..870b5e89f --- /dev/null +++ b/stock_free_quantity/models/product_template.py @@ -0,0 +1,33 @@ +# 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"] + + 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/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..21e16d388 --- /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 import common + + +class TestTemplateFreeQty(common.SavepointCase): + @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 + + + + + + + + +