diff --git a/stock_putaway_product_template/README.rst b/stock_putaway_product_template/README.rst index 30eec09d6..5cccb42c0 100644 --- a/stock_putaway_product_template/README.rst +++ b/stock_putaway_product_template/README.rst @@ -1,6 +1,6 @@ -======================================= -Putaway strategies on product form view -======================================= +====================================== +Product template in putaway strategies +====================================== .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! @@ -14,18 +14,18 @@ Putaway strategies on product form view :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/12.0/stock_putaway_product_form + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.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-12-0/stock-logistics-warehouse-12-0-stock_putaway_product_form + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-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/12.0 + :target: https://runbot.odoo-community.org/runbot/153/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| -This module adds an easy way to modify product-specific putaway strategies from the product view for a better UX. +This module add product template in putaway strategies from the product view to not need defined putaway strategies for all variants. **Table of contents** @@ -35,9 +35,10 @@ This module adds an easy way to modify product-specific putaway strategies from Usage ===== -* In Settings, set "Storage Locations" to True +* In Inventory Settings, set "Storage Locations" to True * User should be in "Manage push and pull inventory flows" -* Open the form view of a product template or a product and use the fields located under the "Inventory" tab +* Inside a product go to "Putaway rules" +* It's possible to define record to template Bug Tracker =========== @@ -45,7 +46,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -67,6 +68,7 @@ Contributors * `Tecnativa `_: * Sergio Teruel + * Víctor Martínez Maintainers ~~~~~~~~~~~ @@ -92,6 +94,6 @@ Current `maintainers `__: |maintainer-kevinkhao| |maintainer-sebastienbeau| -This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. +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 index 1553865ca..69f7babdf 100644 --- a/stock_putaway_product_template/__init__.py +++ b/stock_putaway_product_template/__init__.py @@ -1,5 +1,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models -from . import tests -from .hooks import post_init_hook diff --git a/stock_putaway_product_template/__manifest__.py b/stock_putaway_product_template/__manifest__.py index 9ee31bc46..6af72f212 100644 --- a/stock_putaway_product_template/__manifest__.py +++ b/stock_putaway_product_template/__manifest__.py @@ -1,16 +1,13 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - "name": "Putaway strategies on product form view", - "summary": "Edit putaway strategies directly from the product form view", - "version": "12.0.1.0.0", + "name": "Product template in putaway strategies", + "summary": "Add product template in putaway strategies from the product view", + "version": "13.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"], - "external_dependencies": {"python": ["openupgradelib"]}, - "data": ["views/product.xml"], - "demo": ["demo/putaway_strategies.xml"], + "data": ["views/stock_putaway_rule_views.xml"], "maintainers": ["kevinkhao", "sebastienbeau"], - "post_init_hook": "post_init_hook", } diff --git a/stock_putaway_product_template/demo/putaway_strategies.xml b/stock_putaway_product_template/demo/putaway_strategies.xml deleted file mode 100644 index c1ffcc5f3..000000000 --- a/stock_putaway_product_template/demo/putaway_strategies.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - Putaway Strategy 1 - - - - - - - - - - - - - - Putaway Strategy 2 - - - - - - - - - - - - diff --git a/stock_putaway_product_template/hooks.py b/stock_putaway_product_template/hooks.py deleted file mode 100644 index 3287c519a..000000000 --- a/stock_putaway_product_template/hooks.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020 Tecnativa - Sergio Teruel -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -import logging - -from openupgradelib import openupgrade - -_logger = logging.getLogger(__name__) - - -def post_init_hook(cr, registry): - openupgrade.logged_query( - cr, - """ - UPDATE stock_fixed_putaway_strat sfps - SET product_tmpl_id=pp.product_tmpl_id - FROM product_product pp - WHERE pp.id=sfps.product_id AND - sfps.product_tmpl_id <> pp.product_tmpl_id - """, - ) diff --git a/stock_putaway_product_template/i18n/stock_putaway_product_form.pot b/stock_putaway_product_template/i18n/stock_putaway_product_form.pot deleted file mode 100644 index 652ddc6f9..000000000 --- a/stock_putaway_product_template/i18n/stock_putaway_product_form.pot +++ /dev/null @@ -1,88 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * stock_putaway_product_form -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 12.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_form -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_putaway__product_location_ids -msgid "Fixed Locations Per Product" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model,name:stock_putaway_product_form.model_stock_fixed_putaway_strat -msgid "Fixed Putaway Strategy on Location" -msgstr "" - -#. module: stock_putaway_product_form -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_template_form_putaway -msgid "Keep empty product field to apply strategy to all variants." -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model,name:stock_putaway_product_form.model_product_product -msgid "Product" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model,name:stock_putaway_product_form.model_product_template -msgid "Product Template" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_stock_fixed_putaway_strat__product_tmpl_id -msgid "Product Tmpl" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_product__product_putaway_categ_ids -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_template__product_putaway_categ_ids -msgid "Product putaway strategies by category" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_product__product_tmpl_putaway_ids -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_template__product_tmpl_putaway_ids -msgid "Product putaway strategies by product" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model.fields,field_description:stock_putaway_product_form.field_product_product__product_product_putaway_ids -msgid "Product putaway strategies by product variant" -msgstr "" - -#. module: stock_putaway_product_form -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_template_form_putaway -msgid "Put Away Strategies by category" -msgstr "" - -#. module: stock_putaway_product_form -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_product_form_putaway -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_template_form_putaway -msgid "Put Away Strategies by products" -msgstr "" - -#. module: stock_putaway_product_form -#: model:ir.model,name:stock_putaway_product_form.model_product_putaway -msgid "Put Away Strategy" -msgstr "" - -#. module: stock_putaway_product_form -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_template_form_putaway -msgid "Putaway strategies" -msgstr "" - -#. module: stock_putaway_product_form -#: model_terms:ir.ui.view,arch_db:stock_putaway_product_form.view_template_form_putaway -msgid "The rules defined per product will be applied before the rules defined per product category." -msgstr "" - 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 000000000..9532dcbd4 --- /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 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_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 index 46b77487a..ec67c6f7b 100644 --- a/stock_putaway_product_template/models/__init__.py +++ b/stock_putaway_product_template/models/__init__.py @@ -1,3 +1,3 @@ -from . import product_product -from . import product_template -from . import putaway_strategy +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 000000000..8e7dce477 --- /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/product_product.py b/stock_putaway_product_template/models/product_product.py deleted file mode 100644 index d6bd5d145..000000000 --- a/stock_putaway_product_template/models/product_product.py +++ /dev/null @@ -1,13 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import fields, models - - -class ProductProduct(models.Model): - _inherit = "product.product" - - product_product_putaway_ids = fields.One2many( - comodel_name="stock.fixed.putaway.strat", - inverse_name="product_id", - string="Product putaway strategies by product variant", - ) diff --git a/stock_putaway_product_template/models/product_template.py b/stock_putaway_product_template/models/product_template.py deleted file mode 100644 index 39d4b6893..000000000 --- a/stock_putaway_product_template/models/product_template.py +++ /dev/null @@ -1,58 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import api, fields, models - - -class ProductTemplate(models.Model): - _inherit = "product.template" - - product_tmpl_putaway_ids = fields.One2many( - comodel_name="stock.fixed.putaway.strat", - inverse_name="product_tmpl_id", - string="Product putaway strategies by product", - ) - - product_putaway_categ_ids = fields.Many2many( - comodel_name="stock.fixed.putaway.strat", - string="Product putaway strategies by category", - compute="_compute_putaway_categ_ids", - ) - - def _find_closest_categ_match(self, categ, putaway_lines): - """Returns the putaway line with the nearest product category""" - lines_match_categ = putaway_lines.filtered(lambda r: r.category_id == categ) - if lines_match_categ: - return lines_match_categ[0] - elif categ.parent_id: - return self._find_closest_categ_match(categ.parent_id, putaway_lines) - else: - return self.env["stock.fixed.putaway.strat"] - - def _get_categ_and_parents(self, categ): - parent_categ_iterator = categ - res = self.env["product.category"] - while parent_categ_iterator: - res += parent_categ_iterator - parent_categ_iterator = parent_categ_iterator.parent_id - return res - - @api.depends("categ_id") - def _compute_putaway_categ_ids(self): - """Pay attention to keep only 1 (most specific, - i.e closest to our product category's parents) - putaway.strat per product.putaway""" - for rec in self: - res = self.env["stock.fixed.putaway.strat"] - categ = rec.categ_id - categs = self._get_categ_and_parents(categ) - # get matching lines from our category or its parents - product_putaway_categ_lines = self.env["stock.fixed.putaway.strat"].search( - [("category_id", "in", categs.ids)] - ) - # from these, get the matching putaway.strats and find - # the lowest-level category match - product_putaways = product_putaway_categ_lines.mapped("putaway_id") - for el in product_putaways: - lines = el.fixed_location_ids - res += self._find_closest_categ_match(categ, lines) - rec.product_putaway_categ_ids = res 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 000000000..f2442e763 --- /dev/null +++ b/stock_putaway_product_template/models/stock_location.py @@ -0,0 +1,13 @@ +# 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): + return super( + StockLocation, self.with_context(filter_putaway_rule=True) + )._get_putaway_strategy(product) diff --git a/stock_putaway_product_template/models/putaway_strategy.py b/stock_putaway_product_template/models/stock_putaway_rule.py similarity index 64% rename from stock_putaway_product_template/models/putaway_strategy.py rename to stock_putaway_product_template/models/stock_putaway_rule.py index 1a0411559..02a401ac8 100644 --- a/stock_putaway_product_template/models/putaway_strategy.py +++ b/stock_putaway_product_template/models/stock_putaway_rule.py @@ -1,35 +1,25 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -# Copyright 2020 Sergio Teruel - Tecnativa +# Copyright 2020 Sergio Teruel - Tecnativa +# Copyright 2020 Víctor Martínez - Tecnativa from odoo import api, fields, models -class PutAwayStrategy(models.Model): - _inherit = "product.putaway" - - # Remove product domain to allow to select product templates - product_location_ids = fields.One2many(domain=[]) - - def _get_putaway_rule(self, product): - return super( - PutAwayStrategy, self.with_context(filter_putaway_rule=True) - )._get_putaway_rule(product) - - -class FixedPutAwayStrategy(models.Model): - _inherit = "stock.fixed.putaway.strat" +class StockPutawayRule(models.Model): + _inherit = "stock.putaway.rule" product_tmpl_id = fields.Many2one( comodel_name="product.template", compute="_compute_product_tmpl_id", store=True, - inverse=lambda self: self, + readonly=False, ondelete="cascade", ) @api.depends("product_id") def _compute_product_tmpl_id(self): for rec in self: + rec.product_tmpl_id = False if rec.product_id: rec.product_tmpl_id = rec.product_id.product_tmpl_id else: @@ -38,7 +28,7 @@ class FixedPutAwayStrategy(models.Model): rec.product_tmpl_id = params.get("id", False) def filtered(self, func): - res = super(FixedPutAwayStrategy, self).filtered(func) + res = super(StockPutawayRule, self).filtered(func) if res or not self.env.context.get("filter_putaway_rule"): return res product = func.__closure__[0].cell_contents diff --git a/stock_putaway_product_template/readme/CONTRIBUTORS.rst b/stock_putaway_product_template/readme/CONTRIBUTORS.rst index ae30e064e..c8a035ba5 100644 --- a/stock_putaway_product_template/readme/CONTRIBUTORS.rst +++ b/stock_putaway_product_template/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * `Tecnativa `_: * Sergio Teruel + * Víctor Martínez diff --git a/stock_putaway_product_template/readme/DESCRIPTION.rst b/stock_putaway_product_template/readme/DESCRIPTION.rst index d4507868e..99ae80c30 100644 --- a/stock_putaway_product_template/readme/DESCRIPTION.rst +++ b/stock_putaway_product_template/readme/DESCRIPTION.rst @@ -1 +1 @@ -This module adds an easy way to modify product-specific putaway strategies from the product view for a better UX. +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 index 7657200db..1723ea641 100644 --- a/stock_putaway_product_template/readme/USAGE.rst +++ b/stock_putaway_product_template/readme/USAGE.rst @@ -1,3 +1,4 @@ -* In Settings, set "Storage Locations" to True +* In Inventory Settings, set "Storage Locations" to True * User should be in "Manage push and pull inventory flows" -* Open the form view of a product template or a product and use the fields located under the "Inventory" tab +* Inside a product go to "Putaway rules" +* It's possible to define record to template diff --git a/stock_putaway_product_template/static/description/index.html b/stock_putaway_product_template/static/description/index.html index 8e00f4ce5..135b50142 100644 --- a/stock_putaway_product_template/static/description/index.html +++ b/stock_putaway_product_template/static/description/index.html @@ -4,7 +4,7 @@ -Putaway strategies on product form view +Product template in putaway strategies -
-

Putaway strategies on product form view

+
+

Product template in putaway strategies

-

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

-

This module adds an easy way to modify product-specific putaway strategies from the product view for a better UX.

+

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

    @@ -385,9 +385,10 @@ ul.auto-toc {

    Usage

      -
    • In Settings, set “Storage Locations” to True
    • +
    • In Inventory Settings, set “Storage Locations” to True
    • User should be in “Manage push and pull inventory flows”
    • -
    • Open the form view of a product template or a product and use the fields located under the “Inventory” tab
    • +
    • Inside a product go to “Putaway rules”
    • +
    • It’s possible to define record to template
    @@ -395,7 +396,7 @@ ul.auto-toc {

    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.

    +feedback.

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

    @@ -415,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Tecnativa:
    • Sergio Teruel
    • +
    • Víctor Martínez
@@ -428,7 +430,7 @@ 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.

+

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 index a5b56cbc2..a00cffade 100644 --- a/stock_putaway_product_template/tests/__init__.py +++ b/stock_putaway_product_template/tests/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import test_product_putaway +from . import test_stock_putaway_rule diff --git a/stock_putaway_product_template/tests/test_product_putaway.py b/stock_putaway_product_template/tests/test_product_putaway.py deleted file mode 100644 index f4de9f10f..000000000 --- a/stock_putaway_product_template/tests/test_product_putaway.py +++ /dev/null @@ -1,102 +0,0 @@ -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo.tests.common import TransactionCase - - -class TestProductPutaway(TransactionCase): - def setUp(self): - super().setUp() - self.putawayObj = self.env["product.putaway"] - self.putawayLineObj = self.env["stock.fixed.putaway.strat"] - ProductTemplate = self.env["product.template"] - ProductAttribute = self.env["product.attribute"] - ProductAttributeValue = self.env["product.attribute.value"] - TemplateAttributeLine = self.env["product.template.attribute.line"] - ref = self.env.ref - self.product_tmpl_chair = ref("product.product_product_11_product_template") - self.product_product_chair = ref("product.product_product_11") - self.category_services = ref("product.product_category_3") - self.putaway_line_1 = ref("stock_putaway_product_form.putaway_strat_1_line_1") - self.putaway_line_2 = ref("stock_putaway_product_form.putaway_strat_1_line_2") - self.putaway_line_3 = ref("stock_putaway_product_form.putaway_strat_2_line_1") - self.putaway_line_4 = ref("stock_putaway_product_form.putaway_strat_2_line_2") - - # Add a product with variants - self.template = ProductTemplate.create( - {"name": "Product test", "type": "consu"} - ) - self.size_attribute = ProductAttribute.create( - {"name": "Test size", "sequence": 1} - ) - self.size_m = ProductAttributeValue.create( - {"name": "Size M", "attribute_id": self.size_attribute.id, "sequence": 1} - ) - self.size_l = ProductAttributeValue.create( - {"name": "Size L", "attribute_id": self.size_attribute.id, "sequence": 2} - ) - self.template_attribute_lines = TemplateAttributeLine.create( - { - "product_tmpl_id": self.template.id, - "attribute_id": self.size_attribute.id, - "value_ids": [(6, 0, [self.size_m.id, self.size_l.id])], - } - ) - self.template.create_variant_ids() - - def test_tmpl_has_putaways_from_products(self): - self.assertIn( - self.putaway_line_1, self.product_tmpl_chair.product_tmpl_putaway_ids, - ) - self.putaway_line_1.product_id = self.env["product.product"] - self.assertNotIn( - self.putaway_line_1, self.product_tmpl_chair.product_tmpl_putaway_ids, - ) - - def test_tmpl_has_putaways_from_category_simple(self): - self.assertIn( - self.putaway_line_2, self.product_tmpl_chair.product_putaway_categ_ids, - ) - self.product_tmpl_chair.categ_id = self.category_services - self.assertNotIn( - self.putaway_line_2, self.product_tmpl_chair.product_putaway_categ_ids, - ) - - def test_tmpl_has_putaways_from_category_parent(self): - # chair is under category: all/saleable/office - self.assertIn( - self.putaway_line_3, self.product_tmpl_chair.product_putaway_categ_ids, - ) - self.assertNotIn( - self.putaway_line_4, self.product_tmpl_chair.product_putaway_categ_ids, - ) - - 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} - ) - variant1 = self.template.product_variant_ids[0] - variant2 = self.template.product_variant_ids[1] - putaway = self.putawayObj.create({"name": "Putaway for test"}) - val_list = [ - { - "putaway_id": putaway.id, - "product_tmpl_id": self.template.id, - "fixed_location_id": location1.id, - }, - { - "putaway_id": putaway.id, - "product_id": variant2.id, - "fixed_location_id": location2.id, - }, - ] - self.putawayLineObj.create(val_list) - location_applied = putaway._get_putaway_rule(variant1).fixed_location_id - self.assertEqual(location_applied, location1) - location_applied = putaway._get_putaway_rule(variant2).fixed_location_id - self.assertEqual(location_applied, location2) 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 000000000..1887db464 --- /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.SavepointCase): + @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/product.xml b/stock_putaway_product_template/views/product.xml deleted file mode 100644 index 1102606d2..000000000 --- a/stock_putaway_product_template/views/product.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - product.template.product.form - product.template - - - - -
- - - -

- The rules defined per product will be applied before the rules defined per product category. -

Keep empty product field to apply strategy to all variants.
-

-
- - - - - - - -
- - - - - - - - - -
-
-
-
- - product.product.form.putaway - product.product - - - - - - - - - - - - - - - -
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 000000000..7cf651f98 --- /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)]} + + + + + + +