From baaa7e4922b09493da6983fa9c63ddcb828b2771 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 | 0 stock_inventory_quantity_history/__init__.py | 3 ++ .../__manifest__.py | 16 +++++++ .../models/__init__.py | 4 ++ .../models/stock_move_line.py | 17 +++++++ .../models/stock_quant.py | 17 +++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../tests/__init__.py | 1 + .../tests/test_inventory_quantity_history.py | 23 ++++++++++ .../views/stock_move_line_views.xml | 45 +++++++++++++++++++ 13 files changed, 135 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/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..e69de29bb2d1 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..022af3d6158c --- /dev/null +++ b/stock_inventory_quantity_history/__manifest__.py @@ -0,0 +1,16 @@ +# License AGPL-3.0 or later (http://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..8d83ac871832 --- /dev/null +++ b/stock_inventory_quantity_history/models/stock_move_line.py @@ -0,0 +1,17 @@ +# 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", + 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..4a940496feed --- /dev/null +++ b/stock_inventory_quantity_history/models/stock_quant.py @@ -0,0 +1,17 @@ +# 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["inventory_theoretical_qty"] = self.quantity + move_line_vals["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..312038bf9172 --- /dev/null +++ b/stock_inventory_quantity_history/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +When doing inventories, keep historic of the theoretical and real quantity 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..2f0ce5602129 --- /dev/null +++ b/stock_inventory_quantity_history/views/stock_move_line_views.xml @@ -0,0 +1,45 @@ + + + stock.move.line + + + + + + + + + stock.move.line + + + + + + + + + +