diff --git a/partner_invoicing_mode_at_shipping/tests/common.py b/partner_invoicing_mode_at_shipping/tests/common.py index a2690f3cc9d..17d5192d86f 100644 --- a/partner_invoicing_mode_at_shipping/tests/common.py +++ b/partner_invoicing_mode_at_shipping/tests/common.py @@ -1,34 +1,13 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.addons.partner_invoicing_mode.tests.common import CommonPartnerInvoicingMode -class InvoiceModeAtShippingCommon: +class InvoiceModeAtShippingCommon(CommonPartnerInvoicingMode): @classmethod def setUpClass(cls): super().setUpClass() - cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - cls.partner = cls.env.ref("base.res_partner_1") - cls.product = cls.env.ref("product.product_delivery_01") - cls.so1 = cls.env["sale.order"].create( - { - "partner_id": cls.partner.id, - "partner_invoice_id": cls.partner.id, - "partner_shipping_id": cls.partner.id, - "order_line": [ - ( - 0, - 0, - { - "name": "Line one", - "product_id": cls.product.id, - "product_uom_qty": 4, - "product_uom": cls.product.uom_id.id, - "price_unit": 123, - }, - ) - ], - } - ) + cls._create_order() @classmethod def _create_order(cls): diff --git a/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_at_shipping.py b/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_at_shipping.py index 254929c81d1..4e8578d5019 100644 --- a/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_at_shipping.py +++ b/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_at_shipping.py @@ -1,18 +1,12 @@ # Copyright 2020 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) -from odoo.tests.common import TransactionCase from odoo.tools import mute_logger from .common import InvoiceModeAtShippingCommon -class TestInvoiceModeAtShipping(InvoiceModeAtShippingCommon, TransactionCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls._create_order() - +class TestInvoiceModeAtShipping(InvoiceModeAtShippingCommon): def test_invoice_created_at_shipping(self): """Check that an invoice is created when goods are shipped.""" self.partner.invoicing_mode = "at_shipping" @@ -42,12 +36,12 @@ def test_picking_multi_order_single_invoice(self): """A picking for more than one sale order creating a single invoice""" self.partner.invoicing_mode = "at_shipping" self.partner.one_invoice_per_order = False - so2 = self.so1.copy() - for order in self.so1, so2: + for order in self.so1, self.so2: order.action_confirm() + # Effectively merge both pickings picking = self.so1.picking_ids - so2.picking_ids.move_ids.picking_id = picking + self.so2.picking_ids.move_ids.picking_id = picking # Transfer the remaining picking with moves for move in picking.move_ids: move.quantity = move.product_uom_qty @@ -56,18 +50,18 @@ def test_picking_multi_order_single_invoice(self): picking.with_context(queue_job__no_delay=True).button_validate() self.assertEqual(len(self.so1.invoice_ids), 1) self.assertEqual(self.so1.invoice_ids.state, "posted") - self.assertEqual(self.so1.invoice_ids, so2.invoice_ids) + self.assertEqual(self.so1.invoice_ids, self.so2.invoice_ids) def test_picking_multi_order_multi_invoice(self): """A picking for more than one sale order creates more than one invoice""" self.partner.invoicing_mode = "at_shipping" self.partner.one_invoice_per_order = True - so2 = self.so1.copy() - for order in self.so1, so2: + for order in self.so1, self.so2: order.action_confirm() + # Effectively merge both pickings picking = self.so1.picking_ids - so2.picking_ids.move_ids.picking_id = picking + self.so2.picking_ids.move_ids.picking_id = picking # Transfer the remaining picking with moves for move in picking.move_ids: move.quantity = move.product_uom_qty @@ -76,9 +70,9 @@ def test_picking_multi_order_multi_invoice(self): picking.with_context(queue_job__no_delay=True).button_validate() self.assertEqual(len(self.so1.invoice_ids), 1) self.assertEqual(self.so1.invoice_ids.state, "posted") - self.assertEqual(len(so2.invoice_ids), 1) - self.assertEqual(so2.invoice_ids.state, "posted") - self.assertNotEqual(self.so1.invoice_ids, so2.invoice_ids) + self.assertEqual(len(self.so2.invoice_ids), 1) + self.assertEqual(self.so2.invoice_ids.state, "posted") + self.assertNotEqual(self.so1.invoice_ids, self.so2.invoice_ids) def test_picking_backorder(self): """In case of a backorder, another invoice is created""" @@ -93,6 +87,7 @@ def test_picking_backorder(self): ).button_validate() self.assertEqual(len(self.so1.invoice_ids), 1) self.assertEqual(self.so1.invoice_ids.state, "posted") + # Now process the backorder backorder = self.so1.picking_ids - picking backorder.move_ids.quantity = 2 diff --git a/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_group_delivery.py b/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_group_delivery.py index 7a69359eb9b..94f9c2bb16b 100644 --- a/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_group_delivery.py +++ b/partner_invoicing_mode_at_shipping/tests/test_invoice_mode_group_delivery.py @@ -2,14 +2,13 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.exceptions import ValidationError -from odoo.tests.common import TransactionCase from odoo.addons.queue_job.tests.common import trap_jobs from .common import InvoiceModeAtShippingCommon -class TestInvoiceModeAtShippingGrouped(InvoiceModeAtShippingCommon, TransactionCase): +class TestInvoiceModeAtShippingGrouped(InvoiceModeAtShippingCommon): @classmethod def setUpClass(cls): super().setUpClass()