From c73621f2c072e514fd1006d7ca6ee58e815d4797 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Fri, 18 Nov 2022 11:09:52 +0100 Subject: [PATCH] [ADD] stock_warehouse_relationship: add warehouse id on various model useful for other modules such as stokc_multi_warehouse_security --- stock_warehouse_relationship/README.rst | 108 +++++ stock_warehouse_relationship/__init__.py | 1 + stock_warehouse_relationship/__manifest__.py | 25 + stock_warehouse_relationship/i18n/fr.po | 86 ++++ .../stock_warehouse_relationship copy.pot | 83 ++++ .../i18n/stock_warehouse_relationship.pot | 83 ++++ .../models/__init__.py | 5 + .../models/stock_move.py | 32 ++ .../models/stock_move_line.py | 14 + .../models/stock_picking.py | 17 + .../models/stock_quant.py | 14 + .../models/stock_quant_package.py | 14 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 20 + .../readme/ROADMAP.rst | 1 + .../static/description/index.html | 452 ++++++++++++++++++ .../tests/__init__.py | 0 .../tests/test_warehouse_relationship.py | 184 +++++++ .../views/stock_move.xml | 14 + .../views/stock_move_line.xml | 14 + .../views/stock_quant.xml | 14 + .../views/stock_quant_package.xml | 14 + 22 files changed, 1198 insertions(+) create mode 100644 stock_warehouse_relationship/README.rst create mode 100644 stock_warehouse_relationship/__init__.py create mode 100644 stock_warehouse_relationship/__manifest__.py create mode 100644 stock_warehouse_relationship/i18n/fr.po create mode 100644 stock_warehouse_relationship/i18n/stock_warehouse_relationship copy.pot create mode 100644 stock_warehouse_relationship/i18n/stock_warehouse_relationship.pot create mode 100644 stock_warehouse_relationship/models/__init__.py create mode 100644 stock_warehouse_relationship/models/stock_move.py create mode 100644 stock_warehouse_relationship/models/stock_move_line.py create mode 100644 stock_warehouse_relationship/models/stock_picking.py create mode 100644 stock_warehouse_relationship/models/stock_quant.py create mode 100644 stock_warehouse_relationship/models/stock_quant_package.py create mode 100644 stock_warehouse_relationship/readme/CONTRIBUTORS.rst create mode 100644 stock_warehouse_relationship/readme/DESCRIPTION.rst create mode 100644 stock_warehouse_relationship/readme/ROADMAP.rst create mode 100644 stock_warehouse_relationship/static/description/index.html create mode 100644 stock_warehouse_relationship/tests/__init__.py create mode 100644 stock_warehouse_relationship/tests/test_warehouse_relationship.py create mode 100644 stock_warehouse_relationship/views/stock_move.xml create mode 100644 stock_warehouse_relationship/views/stock_move_line.xml create mode 100644 stock_warehouse_relationship/views/stock_quant.xml create mode 100644 stock_warehouse_relationship/views/stock_quant_package.xml diff --git a/stock_warehouse_relationship/README.rst b/stock_warehouse_relationship/README.rst new file mode 100644 index 000000000..f5cb08e54 --- /dev/null +++ b/stock_warehouse_relationship/README.rst @@ -0,0 +1,108 @@ +============================ +Stock Warehouse relationship +============================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/14.0/stock_warehouse_relationship + :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-14-0/stock-logistics-warehouse-14-0-stock_warehouse_relationship + :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/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add relationship on various stock models to warehouses (`stock.warehouse`). + +This is technical modules to be use as base for other modules such as: + +* **stock_multi_warehouse_security**: Add ir rules to restrict user access to a list of warehouses + +Following models are linked by this module: + +* *stock.picking* +* *stock.move* +* *stock.move.line* +* *stock.quant* +* *stock.quant.package* + +You'll probably like to use `stock_location_warehouse` as well +which add `warehouse_id` on `stock.location`. + +This module is inspired from the experiences of +`stock_multi_warehouse_security `_ +on version 12.0 but has some key differences on user experience: + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +* link inventories to warehouse(s) somehow + +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 +* Pierre Verkest + +Contributors +~~~~~~~~~~~~ + +* `Foodles `_ + + * Pierre Verkest + +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-petrus-v| image:: https://github.com/petrus-v.png?size=40px + :target: https://github.com/petrus-v + :alt: petrus-v + +Current `maintainer `__: + +|maintainer-petrus-v| + +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_warehouse_relationship/__init__.py b/stock_warehouse_relationship/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_warehouse_relationship/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_warehouse_relationship/__manifest__.py b/stock_warehouse_relationship/__manifest__.py new file mode 100644 index 000000000..372409f1b --- /dev/null +++ b/stock_warehouse_relationship/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Stock Warehouse relationship", + "summary": "Technical module to add warehouse_id field on various stock.* models", + "version": "14.0.1.0.0", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Akretion, Pierre Verkest, Odoo Community Association (OCA)", + "maintainers": ["petrus-v"], + "license": "AGPL-3", + "installable": True, + "depends": [ + "stock", + ], + "data": [ + "views/stock_move_line.xml", + "views/stock_move.xml", + "views/stock_quant_package.xml", + "views/stock_quant.xml", + ], + "development_status": "Alpha", +} diff --git a/stock_warehouse_relationship/i18n/fr.po b/stock_warehouse_relationship/i18n/fr.po new file mode 100644 index 000000000..6f203065a --- /dev/null +++ b/stock_warehouse_relationship/i18n/fr.po @@ -0,0 +1,86 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_warehouse_relationship +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__id +msgid "ID" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant_package +msgid "Packages" +msgstr "Colis" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Mouvements d'article (Ligne de mouvement de stock)" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant +msgid "Quants" +msgstr "Quants" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move +msgid "Stock Move" +msgstr "Mouvement de stock" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move_line__warehouse_id +msgid "" +"Technical field depicting the warehouse to consider for the route selection " +"on the next procurement (if any)." +msgstr "" +"Champ technique décrivant l'entrepôt à prendre en compte pour le choix de la " +"route du prochain approvisionnement (s'il y en a un)." + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_picking +msgid "Transfer" +msgstr "Transfert" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__warehouse_id +msgid "Warehouse" +msgstr "Entrepôt" diff --git a/stock_warehouse_relationship/i18n/stock_warehouse_relationship copy.pot b/stock_warehouse_relationship/i18n/stock_warehouse_relationship copy.pot new file mode 100644 index 000000000..d7dd4d091 --- /dev/null +++ b/stock_warehouse_relationship/i18n/stock_warehouse_relationship copy.pot @@ -0,0 +1,83 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_warehouse_relationship +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__id +msgid "ID" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant_package +msgid "Packages" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant +msgid "Quants" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move_line__warehouse_id +msgid "" +"Technical field depicting the warehouse to consider for the route selection " +"on the next procurement (if any)." +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__warehouse_id +msgid "Warehouse" +msgstr "" diff --git a/stock_warehouse_relationship/i18n/stock_warehouse_relationship.pot b/stock_warehouse_relationship/i18n/stock_warehouse_relationship.pot new file mode 100644 index 000000000..d7dd4d091 --- /dev/null +++ b/stock_warehouse_relationship/i18n/stock_warehouse_relationship.pot @@ -0,0 +1,83 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_warehouse_relationship +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__display_name +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__id +msgid "ID" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant____last_update +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant_package +msgid "Packages" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_quant +msgid "Quants" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,help:stock_warehouse_relationship.field_stock_move_line__warehouse_id +msgid "" +"Technical field depicting the warehouse to consider for the route selection " +"on the next procurement (if any)." +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model,name:stock_warehouse_relationship.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_warehouse_relationship +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_move_line__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_picking__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant__warehouse_id +#: model:ir.model.fields,field_description:stock_warehouse_relationship.field_stock_quant_package__warehouse_id +msgid "Warehouse" +msgstr "" diff --git a/stock_warehouse_relationship/models/__init__.py b/stock_warehouse_relationship/models/__init__.py new file mode 100644 index 000000000..9b1527708 --- /dev/null +++ b/stock_warehouse_relationship/models/__init__.py @@ -0,0 +1,5 @@ +from . import stock_move +from . import stock_picking +from . import stock_quant +from . import stock_quant_package +from . import stock_move_line diff --git a/stock_warehouse_relationship/models/stock_move.py b/stock_warehouse_relationship/models/stock_move.py new file mode 100644 index 000000000..c615d89cb --- /dev/null +++ b/stock_warehouse_relationship/models/stock_move.py @@ -0,0 +1,32 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + warehouse_id = fields.Many2one(index=True) + + @api.model + def _get_move_default_warehouse(self, vals): + if vals.get("picking_type_id"): + pick_type = self.env["stock.picking.type"].browse(vals["picking_type_id"]) + wh = pick_type.warehouse_id + else: + locations = self.env["stock.location"].browse( + [vals["location_id"], vals["location_dest_id"]] + ) + whs = locations.mapped("warehouse_id") + wh = len(whs) <= 1 and whs or self.env["stock.warehouse"] + return wh + + @api.model + def create(self, vals): + if not vals.get("warehouse_id"): + wh = self._get_move_default_warehouse(vals) + vals["warehouse_id"] = wh.id or False + return super().create(vals) diff --git a/stock_warehouse_relationship/models/stock_move_line.py b/stock_warehouse_relationship/models/stock_move_line.py new file mode 100644 index 000000000..fe4cc8bf2 --- /dev/null +++ b/stock_warehouse_relationship/models/stock_move_line.py @@ -0,0 +1,14 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + warehouse_id = fields.Many2one( + "stock.warehouse", related="move_id.warehouse_id", store=True, index=True + ) diff --git a/stock_warehouse_relationship/models/stock_picking.py b/stock_warehouse_relationship/models/stock_picking.py new file mode 100644 index 000000000..74c5a29a2 --- /dev/null +++ b/stock_warehouse_relationship/models/stock_picking.py @@ -0,0 +1,17 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + warehouse_id = fields.Many2one( + "stock.warehouse", + related="picking_type_id.warehouse_id", + store=True, + index=True, + ) diff --git a/stock_warehouse_relationship/models/stock_quant.py b/stock_warehouse_relationship/models/stock_quant.py new file mode 100644 index 000000000..2abc674e3 --- /dev/null +++ b/stock_warehouse_relationship/models/stock_quant.py @@ -0,0 +1,14 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockQuant(models.Model): + _inherit = "stock.quant" + + warehouse_id = fields.Many2one( + "stock.warehouse", related="location_id.warehouse_id", store=True, index=True + ) diff --git a/stock_warehouse_relationship/models/stock_quant_package.py b/stock_warehouse_relationship/models/stock_quant_package.py new file mode 100644 index 000000000..6042788b1 --- /dev/null +++ b/stock_warehouse_relationship/models/stock_quant_package.py @@ -0,0 +1,14 @@ +# Copyright (C) 2019 Akretion +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockQuantPackage(models.Model): + _inherit = "stock.quant.package" + + warehouse_id = fields.Many2one( + "stock.warehouse", related="location_id.warehouse_id", store=True, index=True + ) diff --git a/stock_warehouse_relationship/readme/CONTRIBUTORS.rst b/stock_warehouse_relationship/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..c33fa7d72 --- /dev/null +++ b/stock_warehouse_relationship/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Foodles `_ + + * Pierre Verkest diff --git a/stock_warehouse_relationship/readme/DESCRIPTION.rst b/stock_warehouse_relationship/readme/DESCRIPTION.rst new file mode 100644 index 000000000..d8dbc2b3e --- /dev/null +++ b/stock_warehouse_relationship/readme/DESCRIPTION.rst @@ -0,0 +1,20 @@ +This module add relationship on various stock models to warehouses (`stock.warehouse`). + +This is technical modules to be use as base for other modules such as: + +* **stock_multi_warehouse_security**: Add ir rules to restrict user access to a list of warehouses + +Following models are linked by this module: + +* *stock.picking* +* *stock.move* +* *stock.move.line* +* *stock.quant* +* *stock.quant.package* + +You'll probably like to use `stock_location_warehouse` as well +which add `warehouse_id` on `stock.location`. + +This module is inspired from the experiences of +`stock_multi_warehouse_security `_ +on version 12.0 but has some key differences on user experience: diff --git a/stock_warehouse_relationship/readme/ROADMAP.rst b/stock_warehouse_relationship/readme/ROADMAP.rst new file mode 100644 index 000000000..0d380cf8b --- /dev/null +++ b/stock_warehouse_relationship/readme/ROADMAP.rst @@ -0,0 +1 @@ +* link inventories to warehouse(s) somehow diff --git a/stock_warehouse_relationship/static/description/index.html b/stock_warehouse_relationship/static/description/index.html new file mode 100644 index 000000000..2a5aa1e9b --- /dev/null +++ b/stock_warehouse_relationship/static/description/index.html @@ -0,0 +1,452 @@ + + + + + + +Stock Warehouse relationship + + + +
+

Stock Warehouse relationship

+ + +

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

+

This module add relationship on various stock models to warehouses (stock.warehouse).

+

This is technical modules to be use as base for other modules such as:

+
    +
  • stock_multi_warehouse_security: Add ir rules to restrict user access to a list of warehouses
  • +
+

Following models are linked by this module:

+
    +
  • stock.picking
  • +
  • stock.move
  • +
  • stock.move.line
  • +
  • stock.quant
  • +
  • stock.quant.package
  • +
+

You’ll probably like to use stock_location_warehouse as well +which add warehouse_id on stock.location.

+

This module is inspired from the experiences of +stock_multi_warehouse_security +on version 12.0 but has some key differences on user experience:

+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • link inventories to warehouse(s) somehow
  • +
+
+
+

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
  • +
  • Pierre Verkest
  • +
+
+
+

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 maintainer:

+

petrus-v

+

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_warehouse_relationship/tests/__init__.py b/stock_warehouse_relationship/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/stock_warehouse_relationship/tests/test_warehouse_relationship.py b/stock_warehouse_relationship/tests/test_warehouse_relationship.py new file mode 100644 index 000000000..4a69f6d1c --- /dev/null +++ b/stock_warehouse_relationship/tests/test_warehouse_relationship.py @@ -0,0 +1,184 @@ +# Copyright 2022 Foodles (http://www.foodles.co). +# @author Pierre Verkest +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests.common import SavepointCase + + +class TestWarehouseRelationship(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.company_1 = cls.env.ref("base.main_company") + + cls.warehouse_1 = cls.env["stock.warehouse"].create( + { + "name": "Warehouse 1", + "company_id": cls.company_1.id, + "reception_steps": "one_step", + "delivery_steps": "pick_ship", + "code": "WH1", + } + ) + cls.warehouse_2 = cls.env["stock.warehouse"].create( + { + "name": "Warehouse 2", + "company_id": cls.company_1.id, + "reception_steps": "one_step", + "delivery_steps": "pick_ship", + "code": "WH2", + } + ) + cls.warehouses = cls.warehouse_1 | cls.warehouse_2 + cls.suppliers_location = cls.env.ref("stock.stock_location_suppliers") + cls.customers_location = cls.env.ref("stock.stock_location_customers") + + cls.product = cls.env["product.product"].create( + { + "name": "Product for test", + "type": "product", + } + ) + cls.stock_picking_wh_1 = cls._create_picking( + cls.warehouse_1, location_src=cls.suppliers_location + ) + cls.stock_picking_wh_2 = cls._create_picking( + cls.warehouse_2, location_src=cls.suppliers_location + ) + + @classmethod + def _create_picking( + cls, + warehouse, + picking_type=None, + location_src=None, + location_dest=None, + extra_stock_move_params=None, + env=None, + ): + if not extra_stock_move_params: + extra_stock_move_params = {} + + if not picking_type: + picking_type = warehouse.in_type_id + + if not location_src: + location_src = picking_type.default_location_src_id + + if not location_dest: + location_dest = picking_type.default_location_dest_id + + if not env: + env = cls.env + + location_src.ensure_one() + location_dest.ensure_one() + picking = ( + env["stock.picking"] + .with_company(warehouse.company_id) + .create( + { + "picking_type_id": picking_type.id, + "location_id": location_src.id, + "location_dest_id": location_dest.id, + } + ) + ) + env["stock.move"].with_company(warehouse.company_id).create( + dict( + name="a move", + product_id=cls.product.id, + product_uom_qty=5.0, + product_uom=cls.product.uom_id.id, + picking_id=picking.id, + location_id=location_src.id, + location_dest_id=location_dest.id, + **extra_stock_move_params, + ) + ) + return picking + + def test_stock_picking_warehouse_id(self): + self.assertEqual(self.stock_picking_wh_1.warehouse_id, self.warehouse_1) + self.assertEqual(self.stock_picking_wh_2.warehouse_id, self.warehouse_2) + + def test_stock_move_warehouse_id(self): + self.assertEqual( + self.stock_picking_wh_1.move_lines.mapped("warehouse_id"), self.warehouse_1 + ) + self.assertEqual( + self.stock_picking_wh_2.move_lines.mapped("warehouse_id"), self.warehouse_2 + ) + + def test_stock_move_line_warehouse_id(self): + (self.stock_picking_wh_1 | self.stock_picking_wh_2).action_assign() + self.assertEqual( + self.stock_picking_wh_1.move_line_ids.mapped("warehouse_id"), + self.warehouse_1, + ) + self.assertEqual( + self.stock_picking_wh_2.move_line_ids.mapped("warehouse_id"), + self.warehouse_2, + ) + + def test_stock_quant_warehouse_id(self): + pickings = self.stock_picking_wh_1 | self.stock_picking_wh_2 + pickings.action_assign() + pickings.move_lines.write({"quantity_done": 5}) + pickings.button_validate() + + self.assertEqual( + self.env["stock.quant"].search_count( + [("warehouse_id", "=", self.warehouse_1.id)] + ), + 1, + ) + self.assertEqual( + self.env["stock.quant"].search_count( + [("warehouse_id", "=", self.warehouse_2.id)] + ), + 1, + ) + + def test_stock_quant_package_warehouse_id(self): + pickings = self.stock_picking_wh_1 | self.stock_picking_wh_2 + pickings.action_assign() + for picking in pickings: + picking.move_line_ids.write( + { + "result_package_id": self.env["stock.quant.package"] + .create({"name": f"Dest Pack {picking.warehouse_id.name}"}) + .id, + "qty_done": 5, + } + ) + pickings.button_validate() + + self.assertEqual( + self.env["stock.quant.package"].search_count( + [("warehouse_id", "=", self.warehouse_1.id)] + ), + 1, + ) + self.assertEqual( + self.env["stock.quant.package"].search_count( + [("warehouse_id", "=", self.warehouse_2.id)] + ), + 1, + ) + + def test_create_picking_with_picking_type(self): + """improve coverage when picking_type_id is provide while + creating stock move + """ + picking_type = self.warehouse_2.in_type_id + stock_picking = self._create_picking( + self.warehouse_2, + picking_type=picking_type, + location_src=self.suppliers_location, + extra_stock_move_params={"picking_type_id": picking_type.id}, + ) + stock_picking.action_assign() + self.assertEqual( + self.stock_picking_wh_2.move_lines.mapped("warehouse_id"), self.warehouse_2 + ) diff --git a/stock_warehouse_relationship/views/stock_move.xml b/stock_warehouse_relationship/views/stock_move.xml new file mode 100644 index 000000000..69d263c85 --- /dev/null +++ b/stock_warehouse_relationship/views/stock_move.xml @@ -0,0 +1,14 @@ + + + + + stock.move + + + + + + + + + diff --git a/stock_warehouse_relationship/views/stock_move_line.xml b/stock_warehouse_relationship/views/stock_move_line.xml new file mode 100644 index 000000000..bef8671db --- /dev/null +++ b/stock_warehouse_relationship/views/stock_move_line.xml @@ -0,0 +1,14 @@ + + + + + stock.move.line + + + + + + + + + diff --git a/stock_warehouse_relationship/views/stock_quant.xml b/stock_warehouse_relationship/views/stock_quant.xml new file mode 100644 index 000000000..9bd1c32be --- /dev/null +++ b/stock_warehouse_relationship/views/stock_quant.xml @@ -0,0 +1,14 @@ + + + + + stock.quant + + + + + + + + + diff --git a/stock_warehouse_relationship/views/stock_quant_package.xml b/stock_warehouse_relationship/views/stock_quant_package.xml new file mode 100644 index 000000000..a2709d520 --- /dev/null +++ b/stock_warehouse_relationship/views/stock_quant_package.xml @@ -0,0 +1,14 @@ + + + + + stock.quant.package + + + + + + + + +