From 39a19ff54e119b00f36e412b8d50b1d4fb3621af Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 4 Nov 2019 16:46:39 +0100 Subject: [PATCH] [IMP] stock_landed_costs: Adapt tests to work with/without demo data --- addons/stock_landed_costs/tests/common.py | 9 ++----- .../tests/test_stock_landed_costs.py | 25 +++++++++---------- .../tests/test_stock_landed_costs_purchase.py | 18 ++++++------- .../tests/test_stock_landed_costs_rounding.py | 24 +++++++++--------- .../tests/test_stockvaluationlayer.py | 3 ++- 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/addons/stock_landed_costs/tests/common.py b/addons/stock_landed_costs/tests/common.py index ac14bb6745e..273d1a246fd 100644 --- a/addons/stock_landed_costs/tests/common.py +++ b/addons/stock_landed_costs/tests/common.py @@ -7,11 +7,6 @@ from odoo.modules.module import get_module_resource class TestStockLandedCostsCommon(AccountingTestCase): - def _load(self, module, *args): - tools.convert_file(self.cr, 'stock_landed_costs', - get_module_resource(module, *args), - {}, 'init', False, 'test', self.registry._assertion_report) - def setUp(self): super(TestStockLandedCostsCommon, self).setUp() # Objects @@ -21,8 +16,8 @@ class TestStockLandedCostsCommon(AccountingTestCase): self.LandedCost = self.env['stock.landed.cost'] self.CostLine = self.env['stock.landed.cost.lines'] # References - self.supplier_id = self.ref('base.res_partner_2') - self.customer_id = self.ref('base.res_partner_4') + self.supplier_id = self.env['res.partner'].create({'name': 'My Test Supplier'}).id + self.customer_id = self.env['res.partner'].create({'name': 'My Test Customer'}).id self.picking_type_in_id = self.ref('stock.picking_type_in') self.picking_type_out_id = self.ref('stock.picking_type_out') self.supplier_location_id = self.ref('stock.stock_location_suppliers') diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs.py b/addons/stock_landed_costs/tests/test_stock_landed_costs.py index c2ceedf8109..fd366173e4b 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs.py @@ -2,20 +2,18 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon +from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest from odoo.exceptions import ValidationError from odoo.tests import tagged @tagged('post_install', '-at_install') -class TestStockLandedCosts(TestStockLandedCostsCommon): +class TestStockLandedCosts(TestStockLandedCostsCommon, StockAccountMinimalTest): def test_stock_landed_costs(self): # In order to test the landed costs feature of stock, # I create a landed cost, confirm it and check its account move created - self._load('account', 'test', 'account_minimal_test.xml') - self._load('stock_account', 'test', 'stock_valuation_account.xml') - # I create 2 products with different volume and gross weight and configure # them for real_time valuation and fifo costing method product_landed_cost_1 = self.env['product.product'].create({ @@ -24,8 +22,8 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): 'volume': 1, }) product_landed_cost_1.product_tmpl_id.categ_id.property_cost_method = 'fifo' - product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.ref('stock_landed_costs.o_expense') - product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.ref('stock_landed_costs.o_income') + product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.o_expense + product_landed_cost_1.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.o_income product_landed_cost_2 = self.env['product.product'].create({ 'name': "LC product 2", @@ -33,8 +31,8 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): 'volume': 1.5, }) product_landed_cost_2.product_tmpl_id.categ_id.property_cost_method = 'fifo' - product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.ref('stock_landed_costs.o_expense') - product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.ref('stock_landed_costs.o_income') + product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.o_expense + product_landed_cost_2.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.o_income picking_default_vals = self.env['stock.picking'].default_get(list(self.env['stock.picking'].fields_get())) @@ -90,14 +88,15 @@ class TestStockLandedCosts(TestStockLandedCostsCommon): # I create a landed cost for those 2 pickings default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get())) + virtual_home_staging = self.env['product.product'].create({'name': 'Virtual Home Staging'}) default_vals.update({ 'picking_ids': [picking_landed_cost_1.id, picking_landed_cost_2.id], - 'account_journal_id': self.ref('stock_landed_costs.expenses_journal'), + 'account_journal_id': self.expenses_journal, 'cost_lines': [ - (0, 0, {'product_id': self.ref('product.product_product_2')}), - (0, 0, {'product_id': self.ref('product.product_product_2')}), - (0, 0, {'product_id': self.ref('product.product_product_2')}), - (0, 0, {'product_id': self.ref('product.product_product_2')})], + (0, 0, {'product_id': virtual_home_staging.id}), + (0, 0, {'product_id': virtual_home_staging.id}), + (0, 0, {'product_id': virtual_home_staging.id}), + (0, 0, {'product_id': virtual_home_staging.id})], 'valuation_adjustment_lines': [], }) cost_lines_values = { diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py b/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py index 357c56fb7f0..1b5fcd6e27a 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs_purchase.py @@ -2,6 +2,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import unittest from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon +from odoo.addons.stock_account.tests.test_stockvaluation import _create_accounting_data + from odoo.tests import tagged @@ -46,12 +48,15 @@ class TestLandedCosts(TestStockLandedCostsCommon): 'picking_id': self.picking_out.id, 'location_id': self.stock_location_id, 'location_dest_id': self.customer_location_id}) + self.stock_input_account, self.stock_output_account, self.stock_valuation_account, self.expense_account, self.stock_journal = _create_accounting_data(self.env) + self.categ_all.write({ + 'property_stock_account_input_categ_id': self.stock_input_account.id, + 'property_stock_account_output_categ_id': self.stock_output_account.id, + 'property_stock_valuation_account_id': self.stock_valuation_account.id, + 'property_stock_journal': self.stock_journal.id, + }) def test_00_landed_costs_on_incoming_shipment(self): - chart_of_accounts = self.env.company.chart_template_id - generic_coa = self.env.ref('l10n_generic_coa.configurable_chart_template') - if chart_of_accounts != generic_coa: - raise unittest.SkipTest('Skip this test as it works only with %s (%s loaded)' % (generic_coa.name, chart_of_accounts.name)) """ Test landed cost on incoming shipment """ # # (A) Purchase product @@ -101,11 +106,6 @@ class TestLandedCosts(TestStockLandedCostsCommon): self.assertEqual(account_entry['debit'], 430.0, 'Wrong Account Entry') def test_01_negative_landed_costs_on_incoming_shipment(self): - chart_of_accounts = self.env.company.chart_template_id - generic_coa = self.env.ref('l10n_generic_coa.configurable_chart_template') - if chart_of_accounts != generic_coa: - raise unittest.SkipTest('Skip this test as it works only with %s (%s loaded)' % (generic_coa.name, chart_of_accounts.name)) - """ Test negative landed cost on incoming shipment """ # # (A) Purchase Product diff --git a/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py b/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py index 064b3093de4..458a9791e68 100644 --- a/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py +++ b/addons/stock_landed_costs/tests/test_stock_landed_costs_rounding.py @@ -2,18 +2,16 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon +from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest from odoo.tests import tagged @tagged('post_install', '-at_install') -class TestStockLandedCostsRounding(TestStockLandedCostsCommon): +class TestStockLandedCostsRounding(TestStockLandedCostsCommon, StockAccountMinimalTest): def test_stock_landed_costs_rounding(self): # In order to test the rounding in landed costs feature of stock, I create 2 landed cost - self._load('account', 'test', 'account_minimal_test.xml') - self._load('stock_account', 'test', 'stock_valuation_account.xml') - # Define undivisible units product_uom_unit_round_1 = self.env.ref('uom.product_uom_unit') product_uom_unit_round_1.write({ @@ -28,8 +26,8 @@ class TestStockLandedCostsRounding(TestStockLandedCostsCommon): 'uom_id': product_uom_unit_round_1.id, }) product_landed_cost_3.product_tmpl_id.categ_id.property_cost_method = 'fifo' - product_landed_cost_3.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.ref('stock_landed_costs.o_expense') - product_landed_cost_3.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.ref('stock_landed_costs.o_income') + product_landed_cost_3.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.o_expense + product_landed_cost_3.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.o_income product_landed_cost_4 = self.env['product.product'].create({ 'name': "LC product 4", @@ -37,8 +35,8 @@ class TestStockLandedCostsRounding(TestStockLandedCostsCommon): }) product_landed_cost_4.product_tmpl_id.categ_id.property_cost_method = 'fifo' product_landed_cost_4.product_tmpl_id.categ_id.property_valuation = 'real_time' - product_landed_cost_4.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.ref('stock_landed_costs.o_expense') - product_landed_cost_4.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.ref('stock_landed_costs.o_income') + product_landed_cost_4.product_tmpl_id.categ_id.property_stock_account_input_categ_id = self.o_expense + product_landed_cost_4.product_tmpl_id.categ_id.property_stock_account_output_categ_id = self.o_income picking_default_vals = self.env['stock.picking'].default_get(list(self.env['stock.picking'].fields_get())) @@ -87,12 +85,14 @@ class TestStockLandedCostsRounding(TestStockLandedCostsCommon): picking_landed_cost_3.action_assign() picking_landed_cost_3._action_done() + virtual_interior_design = self.env['product.product'].create({'name': 'Virtual Interior Design'}) + # I create a landed cost for picking 3 default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get())) default_vals.update({ 'picking_ids': [picking_landed_cost_3.id], - 'account_journal_id': self.ref('stock_landed_costs.expenses_journal'), - 'cost_lines': [(0, 0, {'product_id': self.ref('product.product_product_1')})], + 'account_journal_id': self.expenses_journal, + 'cost_lines': [(0, 0, {'product_id': virtual_interior_design.id})], 'valuation_adjustment_lines': [], }) stock_landed_cost_2 = self.env['stock.landed.cost'].new(default_vals) @@ -128,8 +128,8 @@ class TestStockLandedCostsRounding(TestStockLandedCostsCommon): default_vals = self.env['stock.landed.cost'].default_get(list(self.env['stock.landed.cost'].fields_get())) default_vals.update({ 'picking_ids': [picking_landed_cost_4.id], - 'account_journal_id': self.ref('stock_landed_costs.expenses_journal'), - 'cost_lines': [(0, 0, {'product_id': self.ref('product.product_product_1')})], + 'account_journal_id': self.expenses_journal, + 'cost_lines': [(0, 0, {'product_id': virtual_interior_design.id})], 'valuation_adjustment_lines': [], }) stock_landed_cost_3 = self.env['stock.landed.cost'].new(default_vals) diff --git a/addons/stock_landed_costs/tests/test_stockvaluationlayer.py b/addons/stock_landed_costs/tests/test_stockvaluationlayer.py index e4cab04936e..66c075858d7 100644 --- a/addons/stock_landed_costs/tests/test_stockvaluationlayer.py +++ b/addons/stock_landed_costs/tests/test_stockvaluationlayer.py @@ -6,9 +6,10 @@ from odoo.tests import Form, tagged from odoo.addons.stock_account.tests.test_stockvaluationlayer import TestStockValuationCommon from odoo.addons.stock_account.tests.test_stockvaluation import _create_accounting_data +from odoo.addons.stock_account.tests.stock_account_minimal_test import StockAccountMinimalTest -class TestStockValuationLC(TestStockValuationCommon): +class TestStockValuationLC(TestStockValuationCommon, StockAccountMinimalTest): @classmethod def setUpClass(cls): super(TestStockValuationLC, cls).setUpClass()