From 9f02782a74911e256d8c44ecbae7f5f10b67850e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 27 Jun 2015 22:04:31 +0200 Subject: [PATCH] [IMP] stock_inventory_preparation_filter: Added tests --- .../tests/__init__.py | 17 ++ ...test_stock_inventory_preparation_filter.py | 147 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 stock_inventory_preparation_filter/tests/__init__.py create mode 100644 stock_inventory_preparation_filter/tests/test_stock_inventory_preparation_filter.py diff --git a/stock_inventory_preparation_filter/tests/__init__.py b/stock_inventory_preparation_filter/tests/__init__.py new file mode 100644 index 000000000000..79299bb5903d --- /dev/null +++ b/stock_inventory_preparation_filter/tests/__init__.py @@ -0,0 +1,17 @@ +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import test_stock_inventory_preparation_filter diff --git a/stock_inventory_preparation_filter/tests/test_stock_inventory_preparation_filter.py b/stock_inventory_preparation_filter/tests/test_stock_inventory_preparation_filter.py new file mode 100644 index 000000000000..5ef493c3f79a --- /dev/null +++ b/stock_inventory_preparation_filter/tests/test_stock_inventory_preparation_filter.py @@ -0,0 +1,147 @@ +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import openerp.tests.common as common + + +class TestStockInventoryPreparationFilterCategories(common.TransactionCase): + + def setUp(self): + super(TestStockInventoryPreparationFilterCategories, self).setUp() + self.inventory_model = self.env['stock.inventory'] + # Create a category + self.category = self.env['product.category'].create( + { + 'name': 'Category for inventory', + 'type': 'normal', + }) + # Create some products in the category + self.product1 = self.env['product.product'].create( + { + 'name': 'Product for inventory 1', + 'type': 'product', + 'categ_id': self.category.id, + 'default_code': 'PROD1', + } + ) + self.product2 = self.env['product.product'].create( + { + 'name': 'Product for inventory 2', + 'type': 'product', + 'categ_id': self.category.id, + 'default_code': 'PROD2', + } + ) + # And have some stock in a location + self.location = self.env['stock.location'].create( + { + 'name': 'Inventory tests', + 'usage': 'internal', + } + ) + inventory = self.inventory_model.create( + { + 'name': 'Product1 inventory', + 'filter': 'product', + 'line_ids': [ + (0, 0, { + 'product_id': self.product1.id, + 'product_uom_id': self.env.ref( + "product.product_uom_unit").id, + 'product_qty': 2.0, + 'location_id': self.location.id, + }), + (0, 0, { + 'product_id': self.product2.id, + 'product_uom_id': self.env.ref( + "product.product_uom_unit").id, + 'product_qty': 4.0, + 'location_id': self.location.id, + }), + ], + }) + inventory.action_done() + + def test_inventory_category_filter(self): + inventory = self.inventory_model.create( + { + 'name': 'Category inventory', + 'filter': 'categories', + 'location_id': self.location.id, + 'categ_ids': [(6, 0, [self.category.id])], + } + ) + inventory.prepare_inventory() + self.assertEqual(len(inventory.line_ids), 2) + line1 = inventory.line_ids[0] + self.assertEqual(line1.product_id, self.product1) + self.assertEqual(line1.theoretical_qty, 2.0) + self.assertEqual(line1.location_id, self.location) + line2 = inventory.line_ids[1] + self.assertEqual(line2.product_id, self.product2) + self.assertEqual(line2.theoretical_qty, 4.0) + self.assertEqual(line2.location_id, self.location) + + def test_inventory_products_filter(self): + inventory = self.inventory_model.create( + { + 'name': 'Products inventory', + 'filter': 'products', + 'location_id': self.location.id, + 'product_ids': [(6, 0, [self.product1.id, self.product2.id])], + } + ) + inventory.prepare_inventory() + self.assertEqual(len(inventory.line_ids), 2) + line1 = inventory.line_ids[0] + self.assertEqual(line1.product_id, self.product1) + self.assertEqual(line1.theoretical_qty, 2.0) + self.assertEqual(line1.location_id, self.location) + line2 = inventory.line_ids[1] + self.assertEqual(line2.product_id, self.product2) + self.assertEqual(line2.theoretical_qty, 4.0) + self.assertEqual(line2.location_id, self.location) + + def test_inventory_empty_filter(self): + inventory = self.inventory_model.create( + { + 'name': 'Products inventory', + 'filter': 'empty', + 'location_id': self.location.id, + 'empty_line_ids': [ + (0, 0, { + 'product_code': 'PROD1', + 'product_qty': 3.0, + }), + (0, 0, { + 'product_code': 'PROD2', + 'product_qty': 7.0, + }), + ], + } + ) + inventory.prepare_inventory() + self.assertEqual(len(inventory.line_ids), 2) + line1 = inventory.line_ids[0] + self.assertEqual(line1.product_id, self.product1) + self.assertEqual(line1.theoretical_qty, 2.0) + self.assertEqual(line1.product_qty, 3.0) + self.assertEqual(line1.location_id, self.location) + line2 = inventory.line_ids[1] + self.assertEqual(line2.product_id, self.product2) + self.assertEqual(line2.theoretical_qty, 4.0) + self.assertEqual(line2.product_qty, 7.0) + self.assertEqual(line2.location_id, self.location)