diff --git a/setup/stock_putaway_product_template/odoo/addons/stock_putaway_product_template b/setup/stock_putaway_product_template/odoo/addons/stock_putaway_product_template new file mode 120000 index 000000000000..2b9ca4b931e1 --- /dev/null +++ b/setup/stock_putaway_product_template/odoo/addons/stock_putaway_product_template @@ -0,0 +1 @@ +../../../../stock_putaway_product_template \ No newline at end of file diff --git a/setup/stock_putaway_product_template/setup.py b/setup/stock_putaway_product_template/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_putaway_product_template/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_putaway_product_template/README.rst b/stock_putaway_product_template/README.rst new file mode 100644 index 000000000000..819fb9384a68 --- /dev/null +++ b/stock_putaway_product_template/README.rst @@ -0,0 +1,100 @@ +====================================== +Product template in putaway strategies +====================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/15.0/stock_putaway_product_template + :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-15-0/stock-logistics-warehouse-15-0-stock_putaway_product_template + :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/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add product template in putaway strategies from the product view to not need defined putaway strategies for all variants. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* In Inventory Settings, set "Storage Locations" to True +* User should be in "Manage push and pull inventory flows" +* Inside a product go to "Putaway rules" +* It's possible to define record to template + +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 +~~~~~~~~~~~~ + +* `Akretion `_: + + * Kevin Khao + +* `Tecnativa `_: + + * Sergio Teruel + * Víctor Martínez + * César A. Sánchez + +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-kevinkhao| image:: https://github.com/kevinkhao.png?size=40px + :target: https://github.com/kevinkhao + :alt: kevinkhao +.. |maintainer-sebastienbeau| image:: https://github.com/sebastienbeau.png?size=40px + :target: https://github.com/sebastienbeau + :alt: sebastienbeau + +Current `maintainers `__: + +|maintainer-kevinkhao| |maintainer-sebastienbeau| + +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_putaway_product_template/__init__.py b/stock_putaway_product_template/__init__.py new file mode 100644 index 000000000000..69f7babdfb1a --- /dev/null +++ b/stock_putaway_product_template/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_putaway_product_template/__manifest__.py b/stock_putaway_product_template/__manifest__.py new file mode 100644 index 000000000000..d9c2b6e4e898 --- /dev/null +++ b/stock_putaway_product_template/__manifest__.py @@ -0,0 +1,13 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Product template in putaway strategies", + "summary": "Add product template in putaway strategies from the product view", + "version": "16.0.1.0.0", + "category": "Inventory", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["stock"], + "data": ["views/stock_putaway_rule_views.xml"], + "maintainers": ["kevinkhao", "sebastienbeau"], +} diff --git a/stock_putaway_product_template/i18n/es.po b/stock_putaway_product_template/i18n/es.po new file mode 100644 index 000000000000..bf81b0bee4f5 --- /dev/null +++ b/stock_putaway_product_template/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_putaway_product_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-11-11 09:02+0000\n" +"PO-Revision-Date: 2023-07-27 11:14+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\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_putaway_product_template +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_product_template__display_name +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_location__display_name +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_putaway_rule__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: stock_putaway_product_template +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_product_template__id +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_location__id +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_putaway_rule__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: stock_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_stock_location +msgid "Inventory Locations" +msgstr "Ubicaciones de inventario" + +#. module: stock_putaway_product_template +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_product_template____last_update +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_location____last_update +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_putaway_rule____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: stock_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: stock_putaway_product_template +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_putaway_rule__product_tmpl_id +msgid "Product Tmpl" +msgstr "Plantilla de producto" + +#. module: stock_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_stock_putaway_rule +msgid "Putaway Rule" +msgstr "Regla de Estrategia de Traslado" diff --git a/stock_putaway_product_template/i18n/stock_putaway_product_template.pot b/stock_putaway_product_template/i18n/stock_putaway_product_template.pot new file mode 100644 index 000000000000..7aadad79a800 --- /dev/null +++ b/stock_putaway_product_template/i18n/stock_putaway_product_template.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_putaway_product_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_product_template +msgid "Product Template" +msgstr "" + +#. module: stock_putaway_product_template +#: model:ir.model.fields,field_description:stock_putaway_product_template.field_stock_putaway_rule__product_tmpl_id +msgid "Product Tmpl" +msgstr "" + +#. module: stock_putaway_product_template +#: model:ir.model,name:stock_putaway_product_template.model_stock_putaway_rule +msgid "Putaway Rule" +msgstr "" diff --git a/stock_putaway_product_template/models/__init__.py b/stock_putaway_product_template/models/__init__.py new file mode 100644 index 000000000000..ec67c6f7bb7e --- /dev/null +++ b/stock_putaway_product_template/models/__init__.py @@ -0,0 +1,3 @@ +from . import product +from . import stock_location +from . import stock_putaway_rule diff --git a/stock_putaway_product_template/models/product.py b/stock_putaway_product_template/models/product.py new file mode 100644 index 000000000000..8e7dce477b5c --- /dev/null +++ b/stock_putaway_product_template/models/product.py @@ -0,0 +1,19 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Copyright 2021 Tecnativa - Víctor Martínez + +from odoo import models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def action_view_related_putaway_rules(self): + self.ensure_one() + domain = [ + "|", + "|", + ("product_tmpl_id", "=", self.id), + ("category_id", "=", self.categ_id.id), + ("product_id.product_tmpl_id", "=", self.id), + ] + return self._get_action_view_related_putaway_rules(domain) diff --git a/stock_putaway_product_template/models/stock_location.py b/stock_putaway_product_template/models/stock_location.py new file mode 100644 index 000000000000..48e66e2f6d95 --- /dev/null +++ b/stock_putaway_product_template/models/stock_location.py @@ -0,0 +1,21 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Copyright 2020 Tecnativa - Sergio Teruel + +from odoo import models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + def _get_putaway_strategy( + self, product, quantity=0, package=None, packaging=None, additional_qty=None + ): + return super( + StockLocation, self.with_context(filter_putaway_rule=True) + )._get_putaway_strategy( + product, + quantity=quantity, + package=package, + packaging=packaging, + additional_qty=additional_qty, + ) diff --git a/stock_putaway_product_template/models/stock_putaway_rule.py b/stock_putaway_product_template/models/stock_putaway_rule.py new file mode 100644 index 000000000000..8214de689d19 --- /dev/null +++ b/stock_putaway_product_template/models/stock_putaway_rule.py @@ -0,0 +1,50 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Copyright 2020 Sergio Teruel - Tecnativa +# Copyright 2020 Víctor Martínez - Tecnativa + +from odoo import api, fields, models + + +class StockPutawayRule(models.Model): + _inherit = "stock.putaway.rule" + + product_tmpl_id = fields.Many2one( + comodel_name="product.template", + compute="_compute_product_tmpl_id", + store=True, + readonly=False, + ondelete="cascade", + ) + + @api.depends("product_id") + def _compute_product_tmpl_id(self): + for rec in self: + if rec.product_id: + rec.product_tmpl_id = rec.product_id.product_tmpl_id + else: + params = self.env.context.get("params", {}) + if params.get("model", "") == "product.template" and params.get("id"): + rec.product_tmpl_id = params.get("id") + + def filtered(self, func): + res = super().filtered(func) + if res or not self.env.context.get("filter_putaway_rule"): + return res + if isinstance(func, str): + name = func + + def func(rec): + any(rec.mapped(name)) + + # populate cache + self.mapped(name) + product = func.__closure__[0].cell_contents + if isinstance(product, str): + return res + if product._name != "product.product": + return res + return self.with_context(filter_putaway_rule=False).filtered( + lambda x: ( + x.product_tmpl_id == product.product_tmpl_id and not x.product_id + ) + ) diff --git a/stock_putaway_product_template/readme/CONTRIBUTORS.rst b/stock_putaway_product_template/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..aa9327f79174 --- /dev/null +++ b/stock_putaway_product_template/readme/CONTRIBUTORS.rst @@ -0,0 +1,9 @@ +* `Akretion `_: + + * Kevin Khao + +* `Tecnativa `_: + + * Sergio Teruel + * Víctor Martínez + * César A. Sánchez diff --git a/stock_putaway_product_template/readme/DESCRIPTION.rst b/stock_putaway_product_template/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..99ae80c301f2 --- /dev/null +++ b/stock_putaway_product_template/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add product template in putaway strategies from the product view to not need defined putaway strategies for all variants. diff --git a/stock_putaway_product_template/readme/USAGE.rst b/stock_putaway_product_template/readme/USAGE.rst new file mode 100644 index 000000000000..1723ea641843 --- /dev/null +++ b/stock_putaway_product_template/readme/USAGE.rst @@ -0,0 +1,4 @@ +* In Inventory Settings, set "Storage Locations" to True +* User should be in "Manage push and pull inventory flows" +* Inside a product go to "Putaway rules" +* It's possible to define record to template diff --git a/stock_putaway_product_template/static/description/icon.png b/stock_putaway_product_template/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_putaway_product_template/static/description/icon.png differ diff --git a/stock_putaway_product_template/static/description/index.html b/stock_putaway_product_template/static/description/index.html new file mode 100644 index 000000000000..8f0d6316a2ba --- /dev/null +++ b/stock_putaway_product_template/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Product template in putaway strategies + + + +
+

Product template in putaway strategies

+ + +

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

+

This module add product template in putaway strategies from the product view to not need defined putaway strategies for all variants.

+

Table of contents

+ +
+

Usage

+
    +
  • In Inventory Settings, set “Storage Locations” to True
  • +
  • User should be in “Manage push and pull inventory flows”
  • +
  • Inside a product go to “Putaway rules”
  • +
  • It’s possible to define record to template
  • +
+
+
+

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.

+

Current maintainers:

+

kevinkhao sebastienbeau

+

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_putaway_product_template/tests/__init__.py b/stock_putaway_product_template/tests/__init__.py new file mode 100644 index 000000000000..a00cffade49c --- /dev/null +++ b/stock_putaway_product_template/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_stock_putaway_rule diff --git a/stock_putaway_product_template/tests/test_stock_putaway_rule.py b/stock_putaway_product_template/tests/test_stock_putaway_rule.py new file mode 100644 index 000000000000..085c50e621c3 --- /dev/null +++ b/stock_putaway_product_template/tests/test_stock_putaway_rule.py @@ -0,0 +1,110 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Copyright 2020 Tecnativa - Sergio Teruel +# Copyright 2020-2021 Víctor Martínez - Tecnativa + +from odoo.tests import common + + +class TestStockPutawayRule(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.putawayRuleObj = cls.env["stock.putaway.rule"] + ProductTemplate = cls.env["product.template"] + ProductAttribute = cls.env["product.attribute"] + ProductAttributeValue = cls.env["product.attribute.value"] + TemplateAttributeLine = cls.env["product.template.attribute.line"] + # Add a product with variants + cls.template = ProductTemplate.create({"name": "Product test", "type": "consu"}) + cls.size_attribute = ProductAttribute.create( + {"name": "Test size", "sequence": 1} + ) + cls.size_m = ProductAttributeValue.create( + {"name": "Size M", "attribute_id": cls.size_attribute.id, "sequence": 1} + ) + cls.size_l = ProductAttributeValue.create( + {"name": "Size L", "attribute_id": cls.size_attribute.id, "sequence": 2} + ) + cls.size_xl = ProductAttributeValue.create( + {"name": "Size XL", "attribute_id": cls.size_attribute.id, "sequence": 3} + ) + cls.template_attribute_lines = TemplateAttributeLine.create( + { + "product_tmpl_id": cls.template.id, + "attribute_id": cls.size_attribute.id, + "value_ids": [(6, 0, [cls.size_m.id, cls.size_l.id, cls.size_xl.id])], + } + ) + cls.template._create_variant_ids() + cls.view_id = cls.env.ref("stock.stock_putaway_list").id + + def _stock_putaway_rule_product(self, location, product): + rule = self.putawayRuleObj.create( + { + "company_id": location.company_id.id, + "product_id": product.id, + "location_in_id": location.id, + "location_out_id": location.id, + } + ) + self.assertEqual(rule.location_in_id, location) + self.assertEqual(rule.product_tmpl_id, product.product_tmpl_id) + self.assertEqual(rule.product_id, product) + return rule + + def _get_product_rules(self, product): + return self.putawayRuleObj.search( + product.action_view_related_putaway_rules()["domain"] + ) + + def test_apply_putaway(self): + # Create one strategy line for product template and other with a + # specific variant + location = self.env.ref("stock.stock_location_shop0") + location1 = location.copy( + {"name": "Location test 1", "location_id": location.id} + ) + location2 = location.copy( + {"name": "Location test 2", "location_id": location.id} + ) + # Create rule according to product_tmpl_id + rule_product = self.putawayRuleObj.create( + { + "company_id": location1.company_id.id, + "product_tmpl_id": self.template.id, + "location_in_id": location1.id, + "location_out_id": location1.id, + } + ) + self.assertEqual(rule_product.location_in_id, location1) + self.assertEqual(rule_product.product_tmpl_id, self.template) + self.assertEqual(rule_product.product_id.id, False) + # Create rules related to variants and diferente locations + variant1 = self.template.product_variant_ids[0] + variant2 = self.template.product_variant_ids[1] + variant3 = self.template.product_variant_ids[2] + self._stock_putaway_rule_product(location1, variant1) + self._stock_putaway_rule_product(location2, variant2) + # Create rule according to category + rule_category = self.putawayRuleObj.create( + { + "company_id": location1.company_id.id, + "category_id": self.template.categ_id.id, + "location_in_id": location1.id, + "location_out_id": location1.id, + } + ) + self.assertEqual(rule_category.category_id, self.template.categ_id) + self.assertEqual(rule_category.location_in_id, location1) + self.assertEqual(rule_category.product_tmpl_id.id, False) + self.assertEqual(rule_category.product_id.id, False) + # Check rules related + self.assertEqual(len(self._get_product_rules(self.template)), 4) + self.assertEqual(len(self._get_product_rules(variant1)), 2) + self.assertEqual(len(self._get_product_rules(variant2)), 2) + self.assertEqual(len(self._get_product_rules(variant3)), 1) + # Check _get_putaway_strategy + locations = location + location.child_ids + self.assertEqual(locations._get_putaway_strategy(variant1), location1) + self.assertEqual(locations._get_putaway_strategy(variant2), location2) + self.assertEqual(locations._get_putaway_strategy(variant3), location1) diff --git a/stock_putaway_product_template/views/stock_putaway_rule_views.xml b/stock_putaway_product_template/views/stock_putaway_rule_views.xml new file mode 100644 index 000000000000..d9852ea5c815 --- /dev/null +++ b/stock_putaway_product_template/views/stock_putaway_rule_views.xml @@ -0,0 +1,31 @@ + + + + + Add product_tmpl_id field + stock.putaway.rule + + + + False + {'readonly': [('category_id', '!=', False)], 'required': [('category_id', '=', False),('product_tmpl_id', '=', False)]} + + + False + {'readonly': ['|', ('product_id', '!=', False), ('product_tmpl_id', '!=', False)], 'required': [('product_id', '=', False),('product_tmpl_id', '=', False)]} + + + + + + +