diff --git a/addons/account/tests/account_test_classes.py b/addons/account/tests/account_test_classes.py index 76f8cd54013..cf37e2493ef 100644 --- a/addons/account/tests/account_test_classes.py +++ b/addons/account/tests/account_test_classes.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from odoo.tests.common import HttpCase +from odoo.exceptions import ValidationError class AccountingTestCase(HttpCase): """ This class extends the base TransactionCase, in order to test the @@ -16,3 +17,14 @@ class AccountingTestCase(HttpCase): domain = [('company_id', '=', self.env.ref('base.main_company').id)] if not self.env['account.account'].search_count(domain): self.skipTest("No Chart of account found") + + def check_complete_move(self, move, theorical_lines): + for aml in move.line_ids: + line = (aml.name, round(aml.debit, 2), round(aml.credit, 2)) + if line in theorical_lines: + theorical_lines.remove(line) + else: + raise ValidationError('Unexpected journal item. (label: %s, debit: %s, credit: %s)' % (aml.name, round(aml.debit, 2), round(aml.credit, 2))) + if theorical_lines: + raise ValidationError('Remaining theorical line (not found). %s)' % ([(aml[0], aml[1], aml[2]) for aml in theorical_lines])) + return True diff --git a/addons/stock_landed_costs/tests/common.py b/addons/stock_landed_costs/tests/common.py index 84f5b0d4817..cdd99228dab 100644 --- a/addons/stock_landed_costs/tests/common.py +++ b/addons/stock_landed_costs/tests/common.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -from odoo.tests import common +from odoo.addons.account.tests.account_test_classes import AccountingTestCase -class TestStockLandedCostsCommon(common.TransactionCase): +class TestStockLandedCostsCommon(AccountingTestCase): def setUp(self): super(TestStockLandedCostsCommon, self).setUp() 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 3aea875c394..f06065512d5 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 @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import odoo from odoo.addons.stock_landed_costs.tests.common import TestStockLandedCostsCommon -@odoo.tests.common.at_install(False) -@odoo.tests.common.post_install(True) class TestLandedCosts(TestStockLandedCostsCommon): def setUp(self): @@ -177,7 +174,44 @@ class TestLandedCosts(TestStockLandedCostsCommon): account_entry = self.env['account.move.line'].read_group( [('move_id', '=', stock_negative_landed_cost.account_move_id.id)], ['debit', 'credit', 'move_id'], ['move_id'])[0] self.assertEqual(account_entry['debit'], account_entry['credit'], 'Debit and credit are not equal') - self.assertEqual(account_entry['debit'], 134.336, 'Wrong Account Entry') + move_lines = [ + ('split by volume - Microwave Oven', 3.75, 0.0), + ('split by volume - Microwave Oven', 0.0, 3.75), + ('split by weight - Microwave Oven', 40.0, 0.0), + ('split by weight - Microwave Oven', 0.0, 40.0), + ('split by quantity - Microwave Oven', 33.33, 0.0), + ('split by quantity - Microwave Oven', 0.0, 33.33), + ('equal split - Microwave Oven', 2.5, 0.0), + ('equal split - Microwave Oven', 0.0, 2.5), + ('split by volume - Refrigerator: 2.0 already out', 0.5, 0.0), + ('split by volume - Refrigerator: 2.0 already out', 0.0, 0.5), + ('split by volume - Refrigerator', 1.25, 0.0), + ('split by volume - Refrigerator', 0.0, 1.25), + ('split by weight - Refrigerator: 2.0 already out', 4.0, 0.0), + ('split by weight - Refrigerator: 2.0 already out', 0.0, 4.0), + ('split by weight - Refrigerator', 10.0, 0.0), + ('split by weight - Refrigerator', 0.0, 10.0), + ('split by quantity - Refrigerator: 2.0 already out', 6.67, 0.0), + ('split by quantity - Refrigerator: 2.0 already out', 0.0, 6.67), + ('split by quantity - Refrigerator', 16.67, 0.0), + ('split by quantity - Refrigerator', 0.0, 16.67), + ('equal split - Refrigerator: 2.0 already out', 1.0, 0.0), + ('equal split - Refrigerator: 2.0 already out', 0.0, 1.0), + ('equal split - Refrigerator', 2.5, 0.0), + ('equal split - Refrigerator', 0.0, 2.5) + ] + if stock_negative_landed_cost.account_move_id.company_id.anglo_saxon_accounting: + move_lines += [ + ('split by volume - Refrigerator: 2.0 already out', 0.5, 0.0), + ('split by volume - Refrigerator: 2.0 already out', 0.0, 0.5), + ('split by weight - Refrigerator: 2.0 already out', 4.0, 0.0), + ('split by weight - Refrigerator: 2.0 already out', 0.0, 4.0), + ('split by quantity - Refrigerator: 2.0 already out', 6.67, 0.0), + ('split by quantity - Refrigerator: 2.0 already out', 0.0, 6.67), + ('equal split - Refrigerator: 2.0 already out', 1.0, 0.0), + ('equal split - Refrigerator: 2.0 already out', 0.0, 1.0), + ] + self.check_complete_move(stock_negative_landed_cost.account_move_id, move_lines) def _process_incoming_shipment(self): """ Two product incoming shipment. """