From bf2dd62a56f454dfa71d6c74606cc9826ed78206 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Tue, 19 Nov 2024 09:08:59 +0100 Subject: [PATCH] [IMP] account_ecotax : remove dependency on AccountTestInvoicingCommon from tests The dependency does not really ease the present test but forces us to put the test as post-installed which cant work as account_ecotax_tax changes the account_ecotax behavior Instead of isolating the tests of account_ecotax, it seems better to get rid of the AccountTestInvoicingCommon dependency. It also speed up the tests. --- account_ecotax/tests/test_ecotax.py | 28 ++++++++++++------------- account_ecotax_tax/tests/test_ecotax.py | 11 +++++----- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/account_ecotax/tests/test_ecotax.py b/account_ecotax/tests/test_ecotax.py index 5308500cb..82e24ac3f 100644 --- a/account_ecotax/tests/test_ecotax.py +++ b/account_ecotax/tests/test_ecotax.py @@ -7,15 +7,13 @@ from random import choice from odoo import Command -from odoo.tests.common import Form, tagged +from odoo.tests.common import Form, TransactionCase -from odoo.addons.account.tests.common import AccountTestInvoicingCommon - -class TestInvoiceEcotaxCommon(AccountTestInvoicingCommon): +class TestInvoiceEcotaxCommon(TransactionCase): @classmethod - def setUpClass(cls, chart_template_ref=None): - super().setUpClass(chart_template_ref) + def setUpClass(cls): + super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) # ACCOUNTING STUFF @@ -105,15 +103,16 @@ def setUpClass(cls, chart_template_ref=None): @classmethod def _make_invoice(cls, products): """Creates a new customer invoice with given products and returns it""" - invoice = cls.init_invoice( - "out_invoice", - partner=cls.invoice_partner, - products=products, - company=cls.env.user.company_id, - taxes=cls.invoice_tax, + move_form = Form( + cls.env["account.move"].with_context(default_move_type="out_invoice") ) - invoice.invoice_line_ids._compute_tax_ids() - invoice.invoice_line_ids._compute_ecotax() + move_form.partner_id = cls.invoice_partner + + for product in products or []: + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = product + + invoice = move_form.save() return invoice @classmethod @@ -407,7 +406,6 @@ def _test_05_product_variants(self): ) -@tagged("-at_install", "post_install") class TestInvoiceEcotax(TestInvoiceEcotaxCommon): def test_01_default_fixed_ecotax(self): self._test_01_default_fixed_ecotax() diff --git a/account_ecotax_tax/tests/test_ecotax.py b/account_ecotax_tax/tests/test_ecotax.py index 7422a2865..a627f7cbd 100644 --- a/account_ecotax_tax/tests/test_ecotax.py +++ b/account_ecotax_tax/tests/test_ecotax.py @@ -1,16 +1,13 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo.tests.common import tagged - from odoo.addons.account_ecotax.tests.test_ecotax import TestInvoiceEcotaxCommon -@tagged("-at_install", "post_install") -class TestInvoiceEcotaxTax(TestInvoiceEcotaxCommon): +class TestInvoiceEcotaxTaxComon(TestInvoiceEcotaxCommon): @classmethod - def setUpClass(cls, chart_template_ref=None): - super().setUpClass(chart_template_ref) + def setUpClass(cls): + super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) # ACCOUNTING STUFF @@ -134,6 +131,8 @@ def setUpClass(cls, chart_template_ref=None): # 2- Weight-based ecotax cls.ecotax_weight.sale_ecotax_ids = cls.invoice_weight_based_ecotax + +class TestInvoiceEcotaxTax(TestInvoiceEcotaxTaxComon): def test_01_default_fixed_ecotax(self): self._test_01_default_fixed_ecotax()