diff --git a/setup/stock_generate_putaway_from_inventory/odoo/addons/stock_generate_putaway_from_inventory b/setup/stock_generate_putaway_from_inventory/odoo/addons/stock_generate_putaway_from_inventory new file mode 120000 index 000000000..f4ad37be2 --- /dev/null +++ b/setup/stock_generate_putaway_from_inventory/odoo/addons/stock_generate_putaway_from_inventory @@ -0,0 +1 @@ +../../../../stock_generate_putaway_from_inventory \ No newline at end of file diff --git a/setup/stock_generate_putaway_from_inventory/setup.py b/setup/stock_generate_putaway_from_inventory/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_generate_putaway_from_inventory/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_generate_putaway_from_inventory/README.rst b/stock_generate_putaway_from_inventory/README.rst new file mode 100644 index 000000000..4e470ddda --- /dev/null +++ b/stock_generate_putaway_from_inventory/README.rst @@ -0,0 +1,100 @@ +===================================== +Stock Generate Putaway from Inventory +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.0/stock_generate_putaway_from_inventory + :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_generate_putaway_from_inventory + :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 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Synchronize a Product Putaway Location from an inventory. Note that this module assumes that there is a one-to-one correspondence between the location and putaway strategy, and if the location currently has no putaway strategy, an error will be raised. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +From a validated stock adjustment, use action -> Generate putaway per product. + +The end result is that the location's putaway strategy will be updated, so that all products (and their locations) from the inventory will show up on the putaway strategy. + +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 +~~~~~~~~~~~~ + +* Pierrick Brun +* David Beal +* Sébastien Beau +* Kevin Khao + +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-pierrickbrun| image:: https://github.com/pierrickbrun.png?size=40px + :target: https://github.com/pierrickbrun + :alt: pierrickbrun +.. |maintainer-bealdav| image:: https://github.com/bealdav.png?size=40px + :target: https://github.com/bealdav + :alt: bealdav +.. |maintainer-sebastienbeau| image:: https://github.com/sebastienbeau.png?size=40px + :target: https://github.com/sebastienbeau + :alt: sebastienbeau +.. |maintainer-kevinkhao| image:: https://github.com/kevinkhao.png?size=40px + :target: https://github.com/kevinkhao + :alt: kevinkhao + +Current `maintainers `__: + +|maintainer-pierrickbrun| |maintainer-bealdav| |maintainer-sebastienbeau| |maintainer-kevinkhao| + +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_generate_putaway_from_inventory/__init__.py b/stock_generate_putaway_from_inventory/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_generate_putaway_from_inventory/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_generate_putaway_from_inventory/__manifest__.py b/stock_generate_putaway_from_inventory/__manifest__.py new file mode 100644 index 000000000..9ca55498f --- /dev/null +++ b/stock_generate_putaway_from_inventory/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2016-18 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Stock Generate Putaway from Inventory", + "summary": "Generate Putaway locations per Product deduced from Inventory", + "version": "14.0.1.0.0", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse", + "depends": ["stock", "stock_location_children"], + "license": "AGPL-3", + "data": ["views/stock_inventory.xml"], + "installable": True, + "maintainers": ["pierrickbrun", "bealdav", "sebastienbeau", "kevinkhao"], +} diff --git a/stock_generate_putaway_from_inventory/i18n/fr.po b/stock_generate_putaway_from_inventory/i18n/fr.po new file mode 100644 index 000000000..8b7f2118e --- /dev/null +++ b/stock_generate_putaway_from_inventory/i18n/fr.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_generate_putaway_from_inventory +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-02-26 13:48+0000\n" +"PO-Revision-Date: 2020-02-26 14:53+0100\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.0.6\n" + +#. module: stock_generate_putaway_from_inventory +#: model:ir.actions.server,name:stock_generate_putaway_from_inventory.action_generate_putaway_strategy +msgid "Generate putaway strategies" +msgstr "Générer les rangements" + +#. module: stock_generate_putaway_from_inventory +#: model:ir.model,name:stock_generate_putaway_from_inventory.model_stock_inventory +msgid "Inventory" +msgstr "Inventaire" + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:53 +#, fuzzy, python-format +msgid "" +"Inventory location doesn't have a putaway strategy. Please set a putaway " +"strategy on the inventory's location." +msgstr "" +"Certains emplacements n'ont pas de stratégie de rangement. Veuillez choisir " +"une stratégie de rangement pour les emplacements suivants: " + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:45 +#, python-format +msgid "Please validate the inventory before generating the putaway strategy." +msgstr "" + +#~ msgid "" +#~ "Some inventories are not validated. Please validate the following " +#~ "inventories: " +#~ msgstr "" +#~ "Certains inventaires ne sont pas validés. Veuillez valider les " +#~ "inventaires suivants: " diff --git a/stock_generate_putaway_from_inventory/i18n/stock_generate_putaway_from_inventory.pot b/stock_generate_putaway_from_inventory/i18n/stock_generate_putaway_from_inventory.pot new file mode 100644 index 000000000..4f14675ea --- /dev/null +++ b/stock_generate_putaway_from_inventory/i18n/stock_generate_putaway_from_inventory.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_generate_putaway_from_inventory +# +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_generate_putaway_from_inventory +#: model:ir.actions.server,name:stock_generate_putaway_from_inventory.action_generate_putaway_strategy +msgid "Generate putaway strategies" +msgstr "" + +#. module: stock_generate_putaway_from_inventory +#: model:ir.model,name:stock_generate_putaway_from_inventory.model_stock_inventory +msgid "Inventory" +msgstr "" + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:53 +#, python-format +msgid "Inventory location doesn't have a putaway strategy. Please set a putaway strategy on the inventory's location." +msgstr "" + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:45 +#, python-format +msgid "Please validate the inventory before generating the putaway strategy." +msgstr "" + diff --git a/stock_generate_putaway_from_inventory/models/__init__.py b/stock_generate_putaway_from_inventory/models/__init__.py new file mode 100644 index 000000000..35536816e --- /dev/null +++ b/stock_generate_putaway_from_inventory/models/__init__.py @@ -0,0 +1 @@ +from . import stock_inventory diff --git a/stock_generate_putaway_from_inventory/models/stock_inventory.py b/stock_generate_putaway_from_inventory/models/stock_inventory.py new file mode 100644 index 000000000..ee6f4d8ec --- /dev/null +++ b/stock_generate_putaway_from_inventory/models/stock_inventory.py @@ -0,0 +1,59 @@ +# © 2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, models +from odoo.exceptions import ValidationError + + +class StockInventory(models.Model): + _inherit = "stock.inventory" + + def action_generate_putaway_rules(self): + self._generate_putaway_rules() + + def _generate_putaway_rules(self): + for record in self: + if record.state != "done": + raise ValidationError( + _( + "Please validate the inventory before generating " + "the putaway strategy." + ) + ) + record.line_ids._generate_putaway_rules(record.location_ids) + + +class StockInventoryLine(models.Model): + _inherit = "stock.inventory.line" + + def _generate_putaway_rules(self, inventory_locations): + # Eliminate lines for other IN locations + # and eliminate lines where quantity is null + for location_in in inventory_locations: + self.filtered( + lambda x: x.product_qty > 0 + and x.location_id.id in location_in.children_ids.ids + )._update_product_putaway_rule(location_in) + + def _update_product_putaway_rule(self, location_in): + putaway_rule_obj = self.env["stock.putaway.rule"] + putaway_rules = putaway_rule_obj.search( + [ + ("product_id", "in", self.mapped("product_id").ids), + ("location_in_id", "=", location_in.id), + ] + ) + for record in self: + putaway_rule = putaway_rules.filtered( + lambda x: x.product_id == record.product_id + ) + if putaway_rule: + putaway_rule.location_out_id = record.location_id + else: + putaway_rule_obj.create( + { + "product_id": record.product_id.id, + "location_in_id": location_in.id, + "location_out_id": record.location_id.id, + } + ) diff --git a/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst b/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..d88f06775 --- /dev/null +++ b/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Pierrick Brun +* David Beal +* Sébastien Beau +* Kevin Khao diff --git a/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst b/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst new file mode 100644 index 000000000..86cd21ff7 --- /dev/null +++ b/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Synchronize a Product Putaway Location from an inventory. Note that this module assumes that there is a one-to-one correspondence between the location and putaway strategy, and if the location currently has no putaway strategy, an error will be raised. diff --git a/stock_generate_putaway_from_inventory/readme/USAGE.rst b/stock_generate_putaway_from_inventory/readme/USAGE.rst new file mode 100644 index 000000000..0545feab9 --- /dev/null +++ b/stock_generate_putaway_from_inventory/readme/USAGE.rst @@ -0,0 +1,3 @@ +From a validated stock adjustment, use action -> Generate putaway per product. + +The end result is that the location's putaway strategy will be updated, so that all products (and their locations) from the inventory will show up on the putaway strategy. diff --git a/stock_generate_putaway_from_inventory/static/description/icon.png b/stock_generate_putaway_from_inventory/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_generate_putaway_from_inventory/static/description/icon.png differ diff --git a/stock_generate_putaway_from_inventory/static/description/index.html b/stock_generate_putaway_from_inventory/static/description/index.html new file mode 100644 index 000000000..e1215f5ca --- /dev/null +++ b/stock_generate_putaway_from_inventory/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Stock Generate Putaway from Inventory + + + +
+

Stock Generate Putaway from Inventory

+ + +

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

+

Synchronize a Product Putaway Location from an inventory. Note that this module assumes that there is a one-to-one correspondence between the location and putaway strategy, and if the location currently has no putaway strategy, an error will be raised.

+

Table of contents

+ +
+

Usage

+

From a validated stock adjustment, use action -> Generate putaway per product.

+

The end result is that the location’s putaway strategy will be updated, so that all products (and their locations) from the inventory will show up on the putaway strategy.

+
+
+

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:

+

pierrickbrun bealdav sebastienbeau kevinkhao

+

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_generate_putaway_from_inventory/tests/__init__.py b/stock_generate_putaway_from_inventory/tests/__init__.py new file mode 100644 index 000000000..29ce34f72 --- /dev/null +++ b/stock_generate_putaway_from_inventory/tests/__init__.py @@ -0,0 +1 @@ +from . import test_generate_putaway diff --git a/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py b/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py new file mode 100644 index 000000000..4dd37979e --- /dev/null +++ b/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py @@ -0,0 +1,61 @@ +# Copyright Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestGeneratePutaway(TransactionCase): + def setUp(self): + super().setUp() + ref = self.env.ref + # demo data + self.inventory_location = ref("stock.stock_location_stock") + self.inventory_location._compute_children_ids() + self.inventory = self.env["stock.inventory"].create( + { + "name": "example inventory", + "location_ids": [(6, 0, [self.inventory_location.id])], + } + ) + self.inventory_line_1_product = ref("product.product_product_24") + self.inventory_line_1_location = ref("stock.stock_location_components") + self.inventory_line_1 = self.env["stock.inventory.line"].create( + { + "product_id": self.inventory_line_1_product.id, + "location_id": self.inventory_line_1_location.id, + "inventory_id": self.inventory.id, + "product_qty": 1, + } + ) + self.irrelevant_location = ref("stock.stock_location_customers") + + def test_error_not_validated(self): + self.inventory.action_cancel_draft() + with self.assertRaises(ValidationError): + self.inventory.action_generate_putaway_rules() + + def test_putaway_line_location_update(self): + putaway = self.env["stock.putaway.rule"].create( + { + "location_out_id": self.irrelevant_location.id, + "location_in_id": self.inventory_location.id, + "product_id": self.inventory_line_1_product.id, + } + ) + self.inventory.action_start() + self.inventory.action_validate() + self.inventory.action_generate_putaway_rules() + self.assertEqual(putaway.location_out_id, self.inventory_line_1_location) + + def test_putaway_line_location_create(self): + self.inventory.action_start() + self.inventory.action_validate() + self.inventory.action_generate_putaway_rules() + putaway = self.env["stock.putaway.rule"].search( + [ + ("product_id", "=", self.inventory_line_1_product.id), + ("location_in_id", "=", self.inventory_location.id), + ] + ) + self.assertEqual(putaway.location_out_id, self.inventory_line_1_location) diff --git a/stock_generate_putaway_from_inventory/views/stock_inventory.xml b/stock_generate_putaway_from_inventory/views/stock_inventory.xml new file mode 100644 index 000000000..5301bcb89 --- /dev/null +++ b/stock_generate_putaway_from_inventory/views/stock_inventory.xml @@ -0,0 +1,12 @@ + + + + Generate putaway strategies + + + code + +records.action_generate_putaway_rules() + + +