From ef0ef6d115be6faf2f144f7e9cad370ff2017f14 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 27 Feb 2020 11:18:36 +0100 Subject: [PATCH] [ADD][12.0] stock_generate_putaway_from_inventory: Add to 12.0 fixup! Simplified exceptions in case inventory is not validated or inventory's location doesn't have a putaway strategy --- .../README.rst | 49 ++++---- .../__init__.py | 1 - .../__manifest__.py | 12 +- .../i18n/fr.po | 40 +++++++ .../stock_generate_putaway_from_inventory.pot | 39 ++++++ .../models/__init__.py | 4 - .../models/stock_inventory.py | 113 ++++++++---------- .../readme/CONTRIBUTORS.rst | 5 +- .../readme/DESCRIPTION.rst | 2 +- .../readme/ROADMAP.rst | 2 - .../readme/USAGE.rst | 7 +- .../static/description/index.html | 53 ++++---- .../tests/__init__.py | 4 - .../tests/test_generate_putaway.py | 96 ++++++++++----- .../views/stock_inventory.xml | 36 ++---- 15 files changed, 275 insertions(+), 188 deletions(-) create mode 100644 stock_generate_putaway_from_inventory/i18n/fr.po create mode 100644 stock_generate_putaway_from_inventory/i18n/stock_generate_putaway_from_inventory.pot delete mode 100644 stock_generate_putaway_from_inventory/readme/ROADMAP.rst diff --git a/stock_generate_putaway_from_inventory/README.rst b/stock_generate_putaway_from_inventory/README.rst index 575c4a649..a0a4e5f97 100644 --- a/stock_generate_putaway_from_inventory/README.rst +++ b/stock_generate_putaway_from_inventory/README.rst @@ -13,13 +13,13 @@ Stock Generate Putaway from Inventory .. |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-akretion%2Fak--odoo--incubator-lightgray.png?logo=github - :target: https://github.com/akretion/ak-odoo-incubator/tree/10.0/stock_generate_putaway_from_inventory - :alt: akretion/ak-odoo-incubator +.. |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 |badge1| |badge2| |badge3| -Generates Product Putaway Location from an inventory. +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** @@ -29,28 +29,17 @@ Generates Product Putaway Location from an inventory. Usage ===== -Before using this module you should specify a putaway strategy on the stock location -you want to generate putaway for. You can find similar instructions on the -stock_putaway_product module which is a dependency. - From a validated stock adjustment, use action -> Generate putaway per product. -Once this is done, the products of the stock adjustment without putaway locations -will have one of the strategy defined on the inventory's location. - -Known issues / Roadmap -====================== - -At the moment, the module only creates putaway locations and does not update -the existing ones. It could be interesing to do so but can be destructive as well +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 `_. +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. @@ -65,11 +54,31 @@ Authors Contributors ~~~~~~~~~~~~ -Pierrick Brun (akretion.com) +* Pierrick Brun +* David Beal +* Sébastien Beau +* Kevin Khao Maintainers ~~~~~~~~~~~ -This module is part of the `akretion/ak-odoo-incubator `_ project on GitHub. +.. |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. diff --git a/stock_generate_putaway_from_inventory/__init__.py b/stock_generate_putaway_from_inventory/__init__.py index a0fdc10fe..0650744f6 100644 --- a/stock_generate_putaway_from_inventory/__init__.py +++ b/stock_generate_putaway_from_inventory/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- from . import models diff --git a/stock_generate_putaway_from_inventory/__manifest__.py b/stock_generate_putaway_from_inventory/__manifest__.py index 55045cfdb..e3ac83e8d 100644 --- a/stock_generate_putaway_from_inventory/__manifest__.py +++ b/stock_generate_putaway_from_inventory/__manifest__.py @@ -1,15 +1,15 @@ -# -*- coding: utf-8 -*- # 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": "10.0.1.0.1", - "author": "Akretion", + "summary": "Generate Putaway locations per Product deduced from Inventory", + "version": "12.0.1.0.0", + "author": "Akretion, Odoo Community Association (OCA)", "category": "Warehouse", - "depends": ["stock_putaway_product"], + "depends": ["stock"], "license": "AGPL-3", - "data": ["views/stock_inventory.xml",], + "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..5ec81ad9c --- /dev/null +++ b/stock_generate_putaway_from_inventory/i18n/fr.po @@ -0,0 +1,40 @@ +# 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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: fr\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:29 +#, python-format +msgid "Some inventories are not validated. Please validate the following inventories: " +msgstr "Certains inventaires ne sont pas validés. Veuillez valider les inventaires suivants: " + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:22 +#, python-format +msgid "Some locations don't have a putaway strategy. Please set a putaway strategy for the locations: " +msgstr "Certains emplacements n'ont pas de stratégie de rangement. Veuillez choisir une stratégie de rangement pour les emplacements 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..d2ae2362a --- /dev/null +++ b/stock_generate_putaway_from_inventory/i18n/stock_generate_putaway_from_inventory.pot @@ -0,0 +1,39 @@ +# 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:47+0000\n" +"PO-Revision-Date: 2020-02-26 13:47+0000\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:29 +#, python-format +msgid "Some inventories are not validated. Please validate the following inventories: " +msgstr "" + +#. module: stock_generate_putaway_from_inventory +#: code:addons/stock_generate_putaway_from_inventory/models/stock_inventory.py:22 +#, python-format +msgid "Some locations don't have a putaway strategy. Please set a putaway strategy for the locations: " +msgstr "" + diff --git a/stock_generate_putaway_from_inventory/models/__init__.py b/stock_generate_putaway_from_inventory/models/__init__.py index 8dc941f4c..35536816e 100644 --- a/stock_generate_putaway_from_inventory/models/__init__.py +++ b/stock_generate_putaway_from_inventory/models/__init__.py @@ -1,5 +1 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-18 Akretion -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - 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 index c4682c22a..75e238fc2 100644 --- a/stock_generate_putaway_from_inventory/models/stock_inventory.py +++ b/stock_generate_putaway_from_inventory/models/stock_inventory.py @@ -1,74 +1,61 @@ -# -*- coding: utf-8 -*- # © 2018 Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, api, _ -from odoo.exceptions import UserError - - -class StockLocation(models.Model): - _inherit = "stock.location" - - def _get_putaway_strategy(self): - if self.putaway_strategy_id: - return self.putaway_strategy_id - elif self.location_id: - return self.location_id._get_putaway_strategy() +from odoo import models, _ +from odoo.exceptions import ValidationError class StockInventory(models.Model): _inherit = "stock.inventory" - @api.multi - def generate_putaway_strategy(self): - putaway_locations = {} + def action_generate_putaway_strategy(self): for inventory in self: - if self.state != "done": - raise UserError( - _("Please, validate the stock adjustment before") - ) - strategy = self.location_id._get_putaway_strategy() - if not strategy: - raise UserError( - _( - "Please, specify a Putaway Strategy " - "on the inventory's location (or a parent one)" - ) - ) - putaway_locations.update(self._prepare_putaway_locations(strategy)) - for putaway_location in putaway_locations.values(): - putaway_location.pop("qty") - self.env["stock.product.putaway.strategy"].create(putaway_location) + inventory._generate_putaway_strategy() - def _prepare_putaway_locations(self, strategy): - self.ensure_one() - putaway_locations = {} + def _get_putaway_strategy(self, loc): + if loc.putaway_strategy_id: + return loc.putaway_strategy_id + elif loc.location_id: + return self._get_putaway_strategy(loc.location_id) + + def _update_product_putaway_strategy(self, inventory_line, strategy): + putaway_line_obj = self.env["stock.fixed.putaway.strat"] + putaway_line = putaway_line_obj.search( + [ + ("product_id", "=", inventory_line.product_id.id), + ("putaway_id", "=", strategy.id), + ] + ) + if putaway_line: + putaway_line.write( + {"fixed_location_id": inventory_line.location_id.id} + ) + else: + putaway_line_obj.create( + { + "product_id": inventory_line.product_id.id, + "fixed_location_id": inventory_line.location_id.id, + "putaway_id": strategy.id, + } + ) + + def _generate_putaway_strategy(self): + if self.state != "done": + raise ValidationError( + _( + "Please validate the inventory before generating " + "the putaway strategy." + ) + ) + putaway = self._get_putaway_strategy(self.location_id) + if not putaway: + raise ValidationError( + _( + "Inventory location doesn't have a putaway strategy. " + "Please set a putaway strategy on the inventory's " + "location." + ) + ) for line in self.line_ids: - if line.product_id.product_putaway_ids: - continue - if ( - line.product_id.id not in putaway_locations - or line.product_qty - > putaway_locations[line.product_id.id]["qty"] - ): - # If there is several lines for a product, we will use the - # one having more products - putaway_locations[ - line.product_id.id - ] = line._prepare_putaway_location(strategy) - return putaway_locations - - -class StockInventoryLine(models.Model): - _inherit = "stock.inventory.line" - - def _prepare_putaway_location(self, strategy): - self.ensure_one() - res = { - "qty": self.product_qty, - "product_product_id": self.product_id.id, - "product_tmpl_id": self.product_id.product_tmpl_id.id, - "fixed_location_id": self.location_id.id, - "putaway_id": strategy.id, - } - return res + if line.product_qty > 0: + self._update_product_putaway_strategy(line, putaway) diff --git a/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst b/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst index ed0365161..536128cd3 100644 --- a/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst +++ b/stock_generate_putaway_from_inventory/readme/CONTRIBUTORS.rst @@ -1 +1,4 @@ -Pierrick Brun (akretion.com) \ No newline at end of file +* Pierrick Brun +* David Beal +* Sébastien Beau +* Kevin Khao \ No newline at end of file diff --git a/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst b/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst index c9f912326..85d8d2855 100644 --- a/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst +++ b/stock_generate_putaway_from_inventory/readme/DESCRIPTION.rst @@ -1 +1 @@ -Generates Product Putaway Location from an inventory. \ No newline at end of file +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. \ No newline at end of file diff --git a/stock_generate_putaway_from_inventory/readme/ROADMAP.rst b/stock_generate_putaway_from_inventory/readme/ROADMAP.rst deleted file mode 100644 index d4a96e4c7..000000000 --- a/stock_generate_putaway_from_inventory/readme/ROADMAP.rst +++ /dev/null @@ -1,2 +0,0 @@ -At the moment, the module only creates putaway locations and does not update -the existing ones. It could be interesing to do so but can be destructive as well diff --git a/stock_generate_putaway_from_inventory/readme/USAGE.rst b/stock_generate_putaway_from_inventory/readme/USAGE.rst index f710ed4cf..0545feab9 100644 --- a/stock_generate_putaway_from_inventory/readme/USAGE.rst +++ b/stock_generate_putaway_from_inventory/readme/USAGE.rst @@ -1,8 +1,3 @@ -Before using this module you should specify a putaway strategy on the stock location -you want to generate putaway for. You can find similar instructions on the -stock_putaway_product module which is a dependency. - From a validated stock adjustment, use action -> Generate putaway per product. -Once this is done, the products of the stock adjustment without putaway locations -will have one of the strategy defined on the inventory's location. +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/index.html b/stock_generate_putaway_from_inventory/static/description/index.html index ed30af4b1..9e895c530 100644 --- a/stock_generate_putaway_from_inventory/static/description/index.html +++ b/stock_generate_putaway_from_inventory/static/description/index.html @@ -3,7 +3,7 @@ - + Stock Generate Putaway from Inventory