Skip to content

Commit

Permalink
[UPD] Update testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
chaule97 committed Jan 3, 2025
1 parent 9521c07 commit f251eb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
27 changes: 3 additions & 24 deletions partner_invoicing_mode_at_shipping/tests/common.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"""
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f251eb5

Please sign in to comment.