|
| 1 | +# Copyright 2022 Tecnativa - Carlos Roca |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 3 | + |
| 4 | +from odoo.tests.common import TransactionCase |
| 5 | + |
| 6 | + |
| 7 | +class TestSaleReportDeliveredVolume(TransactionCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) |
| 12 | + cls.partner = cls.env.ref("base.res_partner_12") |
| 13 | + cls.product = cls.env.ref("product.product_product_9") |
| 14 | + |
| 15 | + # Create a sale order with order lines |
| 16 | + cls.order = cls.env["sale.order"].create( |
| 17 | + { |
| 18 | + "partner_id": cls.partner.id, |
| 19 | + "order_line": [ |
| 20 | + ( |
| 21 | + 0, |
| 22 | + 0, |
| 23 | + { |
| 24 | + "product_id": cls.product.id, |
| 25 | + "product_uom": cls.product.uom_id.id, |
| 26 | + "product_uom_qty": 3.0, |
| 27 | + "qty_delivered": 2.0, |
| 28 | + }, |
| 29 | + ), |
| 30 | + (0, 0, {"display_type": "line_section", "name": "Section"}), |
| 31 | + ( |
| 32 | + 0, |
| 33 | + 0, |
| 34 | + { |
| 35 | + "product_id": cls.product.id, |
| 36 | + "product_uom": cls.product.uom_id.id, |
| 37 | + "product_uom_qty": 5.0, |
| 38 | + "qty_delivered": 4.0, |
| 39 | + }, |
| 40 | + ), |
| 41 | + ], |
| 42 | + } |
| 43 | + ) |
| 44 | + |
| 45 | + def test_volume_delivered_computation(self): |
| 46 | + # Confirm the sale order to generate related sale report entries |
| 47 | + self.order.action_confirm() |
| 48 | + reference_value = f"sale.order,{self.order.id}" |
| 49 | + |
| 50 | + sale_report = self.env["sale.report"].search( |
| 51 | + [("order_reference", "=", reference_value)] |
| 52 | + ) |
| 53 | + self.assertTrue( |
| 54 | + sale_report, |
| 55 | + f"No sale report entries found for order_reference {reference_value}", |
| 56 | + ) |
| 57 | + |
| 58 | + expected_volume = sum( |
| 59 | + [ |
| 60 | + line.product_id.volume |
| 61 | + * line.qty_delivered |
| 62 | + / line.product_uom.factor |
| 63 | + * line.product_id.uom_id.factor |
| 64 | + for line in self.order.order_line |
| 65 | + if line.product_id |
| 66 | + ] |
| 67 | + ) |
| 68 | + |
| 69 | + for report_line in sale_report: |
| 70 | + self.assertAlmostEqual( |
| 71 | + report_line.volume_delivered, |
| 72 | + expected_volume, |
| 73 | + places=2, |
| 74 | + msg=f"Volume delivered mismatch for report line {report_line.id}", |
| 75 | + ) |
0 commit comments