Skip to content

Commit

Permalink
[ADD] stock_inventory_quantity_history : module to keep track of theo…
Browse files Browse the repository at this point in the history
…retical and real qty at the time of an inventory
  • Loading branch information
florian-dacosta committed Apr 12, 2024
1 parent 8b67562 commit baaa7e4
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_inventory_quantity_history/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Empty file.
3 changes: 3 additions & 0 deletions stock_inventory_quantity_history/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
16 changes: 16 additions & 0 deletions stock_inventory_quantity_history/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
4 changes: 4 additions & 0 deletions stock_inventory_quantity_history/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions stock_inventory_quantity_history/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -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",
)
17 changes: 17 additions & 0 deletions stock_inventory_quantity_history/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions stock_inventory_quantity_history/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <florian.dacosta@akretion.com>
1 change: 1 addition & 0 deletions stock_inventory_quantity_history/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When doing inventories, keep historic of the theoretical and real quantity
1 change: 1 addition & 0 deletions stock_inventory_quantity_history/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_inventory_quantity_history
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions stock_inventory_quantity_history/views/stock_move_line_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<odoo>
<record id="stock_move_line_form" model="ir.ui.view">
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_move_line_form" />
<field name="arch" type="xml">
<field name="lot_id" position="before">
<label
for="inventory_theoretical_qty"
string="Theoretical Quantity"
/>
<div class="o_row">
<field name="inventory_theoretical_qty" />
<field
name="product_uom_id"
options="{'no_create': True}"
string="Unit of Measure"
groups="uom.group_uom"
/>
</div>
<label for="inventory_real_qty" string="Real Quantity" />
<div class="o_row">
<field name="inventory_real_qty" />
<field
name="product_uom_id"
options="{'no_create': True}"
string="Unit of Measure"
groups="uom.group_uom"
/>
</div>
</field>
</field>
</record>

<record id="stock_move_line_tree" model="ir.ui.view">
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_move_line_tree" />
<field name="arch" type="xml">
<field name="qty_done" position="after">
<field name="inventory_theoretical_qty" optional="hide" />
<field name="inventory_real_qty" optional="hide" />
</field>
</field>
</record>

</odoo>

0 comments on commit baaa7e4

Please sign in to comment.