From 64ddd4b87a388599478241c4933ae8950a43fe2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Wed, 5 May 2021 14:33:03 +0200 Subject: [PATCH] [IMP] stock_quantity_history_location: Add functions in test to allow re-use by othher addons --- .../tests/common.py | 28 ++++++++++++++++++ .../test_stock_quantity_history_location.py | 29 +++++-------------- .../wizards/stock_quantity_history.py | 2 ++ 3 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 stock_quantity_history_location/tests/common.py diff --git a/stock_quantity_history_location/tests/common.py b/stock_quantity_history_location/tests/common.py new file mode 100644 index 0000000..b029621 --- /dev/null +++ b/stock_quantity_history_location/tests/common.py @@ -0,0 +1,28 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + + +class TestCommon(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + def _create_stock_move(self, location_dest_id, qty): + move = self.env["stock.move"].create( + { + "name": "Stock move in", + "location_id": self.supplier_location.id, + "location_dest_id": location_dest_id.id, + "product_id": self.product.id, + "product_uom": self.product.uom_id.id, + "product_uom_qty": qty, + } + ) + move._action_confirm() + move._action_assign() + move_line = move.move_line_ids[0] + move_line.qty_done = qty + move._action_done() + return move diff --git a/stock_quantity_history_location/tests/test_stock_quantity_history_location.py b/stock_quantity_history_location/tests/test_stock_quantity_history_location.py index 83d86b4..f6038a0 100644 --- a/stock_quantity_history_location/tests/test_stock_quantity_history_location.py +++ b/stock_quantity_history_location/tests/test_stock_quantity_history_location.py @@ -1,13 +1,16 @@ # Copyright 2019 ForgeFlow S.L. +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import SavepointCase +from odoo import fields + +from .common import TestCommon -class TestStockQuantityHistoryLocation(SavepointCase): +class TestStockQuantityHistoryLocation(TestCommon): @classmethod def setUpClass(cls): - super(TestStockQuantityHistoryLocation, cls).setUpClass() + super().setUpClass() cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") cls.main_company = cls.env.ref("base.main_company") cls.product = cls.env.ref("product.product_product_3") @@ -26,30 +29,14 @@ class TestStockQuantityHistoryLocation(SavepointCase): "company_id": cls.main_company.id, } ) - # Create a move for the past - move = cls.env["stock.move"].create( - { - "name": "Stock move in", - "location_id": cls.supplier_location.id, - "location_dest_id": cls.child_test_stock_loc.id, - "product_id": cls.product.id, - "product_uom": cls.product.uom_id.id, - "product_uom_qty": 100.0, - } - ) - move._action_confirm() - move._action_assign() - move_line = move.move_line_ids[0] - move_line.qty_done = 100.0 - move._action_done() - move.date = "2019-08-11" + cls._create_stock_move(cls, location_dest_id=cls.child_test_stock_loc, qty=100) def test_wizard_past_date(self): wizard = self.env["stock.quantity.history"].create( { "location_id": self.test_stock_loc.id, "include_child_locations": True, - "inventory_datetime": "2019-08-12 00:00:00", + "inventory_datetime": fields.Datetime.now(), } ) action = wizard.with_context(company_owned=True).open_at_date() diff --git a/stock_quantity_history_location/wizards/stock_quantity_history.py b/stock_quantity_history_location/wizards/stock_quantity_history.py index 2d831bc..623a910 100644 --- a/stock_quantity_history_location/wizards/stock_quantity_history.py +++ b/stock_quantity_history_location/wizards/stock_quantity_history.py @@ -1,6 +1,8 @@ # Copyright 2019 ForgeFlow S.L. # Copyright 2019 Aleph Objects, Inc. +# Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from odoo import fields, models