|
| 1 | +# Copyright 2020 Camptocamp SA |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) |
| 3 | + |
| 4 | +from odoo.tests.common import SavepointCase |
| 5 | + |
| 6 | + |
| 7 | +class TestInvoiceGroupBySaleOrder(SavepointCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.partner_1 = cls.env.ref("base.res_partner_1") |
| 12 | + cls.product_1 = cls.env.ref("product.product_product_1") |
| 13 | + cls.product_1.invoice_policy = "order" |
| 14 | + cls.order1_p1 = cls.env["sale.order"].create( |
| 15 | + { |
| 16 | + "partner_id": cls.partner_1.id, |
| 17 | + "partner_shipping_id": cls.partner_1.id, |
| 18 | + "partner_invoice_id": cls.partner_1.id, |
| 19 | + "client_order_ref": "ref123", |
| 20 | + "order_line": [ |
| 21 | + ( |
| 22 | + 0, |
| 23 | + 0, |
| 24 | + { |
| 25 | + "name": "order 1 line 1", |
| 26 | + "product_id": cls.product_1.id, |
| 27 | + "price_unit": 20, |
| 28 | + "product_uom_qty": 1, |
| 29 | + "product_uom": cls.product_1.uom_id.id, |
| 30 | + }, |
| 31 | + ), |
| 32 | + ( |
| 33 | + 0, |
| 34 | + 0, |
| 35 | + { |
| 36 | + "name": "order 1 line 2", |
| 37 | + "product_id": cls.product_1.id, |
| 38 | + "price_unit": 20, |
| 39 | + "product_uom_qty": 1, |
| 40 | + "product_uom": cls.product_1.uom_id.id, |
| 41 | + }, |
| 42 | + ), |
| 43 | + ], |
| 44 | + } |
| 45 | + ) |
| 46 | + cls.order1_p1.action_confirm() |
| 47 | + cls.order2_p1 = cls.env["sale.order"].create( |
| 48 | + { |
| 49 | + "partner_id": cls.partner_1.id, |
| 50 | + "partner_shipping_id": cls.partner_1.id, |
| 51 | + "partner_invoice_id": cls.partner_1.id, |
| 52 | + "order_line": [ |
| 53 | + ( |
| 54 | + 0, |
| 55 | + 0, |
| 56 | + { |
| 57 | + "name": "order 2 line 1", |
| 58 | + "product_id": cls.product_1.id, |
| 59 | + "price_unit": 20, |
| 60 | + "product_uom_qty": 1, |
| 61 | + "product_uom": cls.product_1.uom_id.id, |
| 62 | + }, |
| 63 | + ), |
| 64 | + ( |
| 65 | + 0, |
| 66 | + 0, |
| 67 | + { |
| 68 | + "name": "order 2 line 2", |
| 69 | + "product_id": cls.product_1.id, |
| 70 | + "price_unit": 20, |
| 71 | + "product_uom_qty": 1, |
| 72 | + "product_uom": cls.product_1.uom_id.id, |
| 73 | + }, |
| 74 | + ), |
| 75 | + ], |
| 76 | + } |
| 77 | + ) |
| 78 | + cls.order2_p1.action_confirm() |
| 79 | + |
| 80 | + def test_create_invoice(self): |
| 81 | + """ Check invoice is generated with sale order sections.""" |
| 82 | + result = { |
| 83 | + 0: "".join([self.order1_p1.name, " - ", self.order1_p1.client_order_ref]), |
| 84 | + 1: "order 1 line 1", |
| 85 | + 2: "order 1 line 2", |
| 86 | + 3: self.order2_p1.name, |
| 87 | + 4: "order 2 line 1", |
| 88 | + 5: "order 2 line 2", |
| 89 | + } |
| 90 | + invoice_ids = (self.order1_p1 + self.order2_p1)._create_invoices() |
| 91 | + lines = ( |
| 92 | + invoice_ids[0] |
| 93 | + .line_ids.sorted("sequence") |
| 94 | + .filtered(lambda r: not r.exclude_from_invoice_tab) |
| 95 | + ) |
| 96 | + for idx, line in enumerate(lines): |
| 97 | + self.assertEqual(line.name, result[idx]) |
| 98 | + |
| 99 | + def test_create_invoice_no_section(self): |
| 100 | + """ Check invoice for only one sale order |
| 101 | +
|
| 102 | + No need to create sections |
| 103 | +
|
| 104 | + """ |
| 105 | + invoice_id = (self.order1_p1)._create_invoices() |
| 106 | + line_sections = invoice_id.line_ids.filtered( |
| 107 | + lambda r: r.display_type == "line_section" |
| 108 | + ) |
| 109 | + self.assertEqual(len(line_sections), 0) |
0 commit comments