From 5d1ed96fe3db306c2220ee6d46811a29896881ce Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 13 Apr 2023 12:38:11 +0200 Subject: [PATCH] [ADD] stock_inventory_quantity_history : module to keep track of theoretical and real qty at the time of an inventory --- .../addons/stock_inventory_quantity_history | 1 + .../stock_inventory_quantity_history/setup.py | 6 + stock_inventory_quantity_history/README.rst | 82 ++++ stock_inventory_quantity_history/__init__.py | 3 + .../__manifest__.py | 17 + .../models/__init__.py | 4 + .../models/stock_move_line.py | 18 + .../models/stock_quant.py | 21 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 2 + .../static/description/index.html | 427 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_inventory_quantity_history.py | 23 + .../views/stock_move_line_views.xml | 42 ++ 15 files changed, 649 insertions(+) create mode 120000 setup/stock_inventory_quantity_history/odoo/addons/stock_inventory_quantity_history create mode 100644 setup/stock_inventory_quantity_history/setup.py create mode 100644 stock_inventory_quantity_history/README.rst create mode 100644 stock_inventory_quantity_history/__init__.py create mode 100644 stock_inventory_quantity_history/__manifest__.py create mode 100644 stock_inventory_quantity_history/models/__init__.py create mode 100644 stock_inventory_quantity_history/models/stock_move_line.py create mode 100644 stock_inventory_quantity_history/models/stock_quant.py create mode 100644 stock_inventory_quantity_history/readme/CONTRIBUTORS.rst create mode 100644 stock_inventory_quantity_history/readme/DESCRIPTION.rst create mode 100644 stock_inventory_quantity_history/readme/USAGE.rst create mode 100644 stock_inventory_quantity_history/static/description/index.html create mode 100644 stock_inventory_quantity_history/tests/__init__.py create mode 100644 stock_inventory_quantity_history/tests/test_inventory_quantity_history.py create mode 100644 stock_inventory_quantity_history/views/stock_move_line_views.xml diff --git a/setup/stock_inventory_quantity_history/odoo/addons/stock_inventory_quantity_history b/setup/stock_inventory_quantity_history/odoo/addons/stock_inventory_quantity_history new file mode 120000 index 000000000000..78178e5e49cd --- /dev/null +++ b/setup/stock_inventory_quantity_history/odoo/addons/stock_inventory_quantity_history @@ -0,0 +1 @@ +../../../../stock_inventory_quantity_history \ No newline at end of file diff --git a/setup/stock_inventory_quantity_history/setup.py b/setup/stock_inventory_quantity_history/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_inventory_quantity_history/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_inventory_quantity_history/README.rst b/stock_inventory_quantity_history/README.rst new file mode 100644 index 000000000000..f0d7658c18eb --- /dev/null +++ b/stock_inventory_quantity_history/README.rst @@ -0,0 +1,82 @@ +============================================ +Stock Inventory Theoretical Quantity History +============================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e488fdd71dcc2f2221822c3c2284e3c3e4b7883580a8cb65e7bee28763b48f43 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/stock_inventory_quantity_history + :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-16-0/stock-logistics-warehouse-16-0-stock_inventory_quantity_history + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When doing inventories, keep history of the theoretical and real quantity + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +After validating an inventory, you can go to Inventory => Reporting => Moves History +On this screen you will find the 2 new fields containing the Theoretical and real quantity at the time the inventory was made. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Florian da Costa + +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. + +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_inventory_quantity_history/__init__.py b/stock_inventory_quantity_history/__init__.py new file mode 100644 index 000000000000..69f7babdfb1a --- /dev/null +++ b/stock_inventory_quantity_history/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_inventory_quantity_history/__manifest__.py b/stock_inventory_quantity_history/__manifest__.py new file mode 100644 index 000000000000..3b478699c168 --- /dev/null +++ b/stock_inventory_quantity_history/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 Akretion France (http://www.akretion.com/) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Inventory Theoretical Quantity History", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "summary": "Keep theoretical and real quantities history", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse Management", + "depends": ["stock"], + "data": [ + "views/stock_move_line_views.xml", + ], + "installable": True, +} diff --git a/stock_inventory_quantity_history/models/__init__.py b/stock_inventory_quantity_history/models/__init__.py new file mode 100644 index 000000000000..c6c25b6ab681 --- /dev/null +++ b/stock_inventory_quantity_history/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import stock_quant +from . import stock_move_line diff --git a/stock_inventory_quantity_history/models/stock_move_line.py b/stock_inventory_quantity_history/models/stock_move_line.py new file mode 100644 index 000000000000..3bc839d633ad --- /dev/null +++ b/stock_inventory_quantity_history/models/stock_move_line.py @@ -0,0 +1,18 @@ +# 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" + + inventory_theoretical_qty = fields.Float( + digits="Product Unit of Measure", + readonly=True, + help="Theoretical Quantity right before the inventory", + ) + inventory_real_qty = fields.Float( + digits="Product Unit of Measure", + readonly=True, + help="Real Quantity at the time of the inventory", + ) diff --git a/stock_inventory_quantity_history/models/stock_quant.py b/stock_inventory_quantity_history/models/stock_quant.py new file mode 100644 index 000000000000..59069c27c150 --- /dev/null +++ b/stock_inventory_quantity_history/models/stock_quant.py @@ -0,0 +1,21 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockQuant(models.Model): + _inherit = "stock.quant" + + def _get_inventory_move_values(self, qty, location_id, location_dest_id, out=False): + vals = super()._get_inventory_move_values( + qty, location_id, location_dest_id, out=out + ) + move_line_vals = vals["move_line_ids"][0][2] + # quantity before the adjustment + move_line_vals.update( + { + "inventory_theoretical_qty": self.quantity, + "inventory_real_qty": self.inventory_quantity, + } + ) + return vals diff --git a/stock_inventory_quantity_history/readme/CONTRIBUTORS.rst b/stock_inventory_quantity_history/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..0bddb053ae41 --- /dev/null +++ b/stock_inventory_quantity_history/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florian da Costa diff --git a/stock_inventory_quantity_history/readme/DESCRIPTION.rst b/stock_inventory_quantity_history/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..542c92057081 --- /dev/null +++ b/stock_inventory_quantity_history/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +When doing inventories, keep history of the theoretical and real quantity diff --git a/stock_inventory_quantity_history/readme/USAGE.rst b/stock_inventory_quantity_history/readme/USAGE.rst new file mode 100644 index 000000000000..2d1ddd15bdb6 --- /dev/null +++ b/stock_inventory_quantity_history/readme/USAGE.rst @@ -0,0 +1,2 @@ +After validating an inventory, you can go to Inventory => Reporting => Moves History +On this screen you will find the 2 new fields containing the Theoretical and real quantity at the time the inventory was made. diff --git a/stock_inventory_quantity_history/static/description/index.html b/stock_inventory_quantity_history/static/description/index.html new file mode 100644 index 000000000000..8ec7c2af12c8 --- /dev/null +++ b/stock_inventory_quantity_history/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +Stock Inventory Theoretical Quantity History + + + +
+

Stock Inventory Theoretical Quantity History

+ + +

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

+

When doing inventories, keep history of the theoretical and real quantity

+

Table of contents

+ +
+

Usage

+

After validating an inventory, you can go to Inventory => Reporting => Moves History +On this screen you will find the 2 new fields containing the Theoretical and real quantity at the time the inventory was made.

+
+
+

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 to smash 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.

+

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_inventory_quantity_history/tests/__init__.py b/stock_inventory_quantity_history/tests/__init__.py new file mode 100644 index 000000000000..abef58942e40 --- /dev/null +++ b/stock_inventory_quantity_history/tests/__init__.py @@ -0,0 +1 @@ +from . import test_inventory_quantity_history diff --git a/stock_inventory_quantity_history/tests/test_inventory_quantity_history.py b/stock_inventory_quantity_history/tests/test_inventory_quantity_history.py new file mode 100644 index 000000000000..bf95eea37356 --- /dev/null +++ b/stock_inventory_quantity_history/tests/test_inventory_quantity_history.py @@ -0,0 +1,23 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestInventoryQuantityHistory(TransactionCase): + def test_inventory_theoretical_quantity(self): + product = self.env.ref("product.product_product_8") + self.env["stock.quant"].with_context(inventory_mode=True).create( + { + "product_id": product.id, + "location_id": self.env.ref("stock.stock_location_stock").id, + "inventory_quantity": 32.0, + } + )._apply_inventory() + history_sml = self.env["stock.move.line"].search( + [("product_id", "=", product.id), ("is_inventory", "=", True)], + order="id desc", + limit=1, + ) + self.assertEqual(history_sml.inventory_theoretical_qty, 0.0) + self.assertEqual(history_sml.inventory_real_qty, 32.0) diff --git a/stock_inventory_quantity_history/views/stock_move_line_views.xml b/stock_inventory_quantity_history/views/stock_move_line_views.xml new file mode 100644 index 000000000000..308f36afb787 --- /dev/null +++ b/stock_inventory_quantity_history/views/stock_move_line_views.xml @@ -0,0 +1,42 @@ + + + stock.move.line + + + + + + + + + stock.move.line + + + + + + + + + +