Skip to content

Commit

Permalink
[ADD] stock_inventory_justification: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBinsfeld committed Jan 8, 2024
1 parent 6305608 commit f8934eb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_inventory_justification/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_inventory_justification
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.stock.tests.common2 import TestStockCommon


class TestStockInventoryJustification(TestStockCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
# MODELS
cls.stock_inventory_justification_model = cls.env[
"stock.inventory.justification"
]
cls.stock_quant_model = cls.env["stock.quant"].with_context(inventory_mode=True)
# INSTANCES
# Inventory justifications
cls.inventory_justification_01 = cls.stock_inventory_justification_model.create(
{"name": "Justification 01"}
)
cls.inventory_justification_02 = cls.stock_inventory_justification_model.create(
{"name": "Justification 02"}
)
# Products
cls.product_1.type = "product"

def test_01(self):
"""
Test case:
- Process a stock inventory on a quant without justification
Expected result:
- The created move has no inventory justification
"""
inventory_quant = self.stock_quant_model.create(
{
"product_id": self.product_1.id,
"inventory_quantity": 50.0,
"location_id": self.warehouse_1.lot_stock_id.id,
}
)
inventory_quant.action_apply_inventory()
stock_move = self.env["stock.move"].search(
[("is_inventory", "=", True), ("product_id", "=", self.product_1.id)]
)
self.assertFalse(stock_move.inventory_justification_ids)

def test_02(self):
"""
Test case:
- Process a stock inventory on a quant with justification
Expected result:
- The created move has the same inventory justification as the quant
"""
inventory_quant = self.stock_quant_model.create(
{
"product_id": self.product_1.id,
"inventory_quantity": 50.0,
"location_id": self.warehouse_1.lot_stock_id.id,
"inventory_justification_ids": [
(6, 0, [self.inventory_justification_01.id])
],
}
)
inventory_quant.action_apply_inventory()
stock_move = self.env["stock.move"].search(
[("is_inventory", "=", True), ("product_id", "=", self.product_1.id)]
)
self.assertFalse(inventory_quant.inventory_justification_ids)
self.assertEqual(
stock_move.inventory_justification_ids, self.inventory_justification_01
)

0 comments on commit f8934eb

Please sign in to comment.