|
| 1 | +# Copyright 2023 Moduon Team S.L. |
| 2 | +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) |
| 3 | + |
| 4 | +from odoo.tests import TransactionCase |
| 5 | + |
| 6 | + |
| 7 | +class TestSaleReportPackaging(TransactionCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super().setUpClass() |
| 11 | + cls.partner = cls.env.ref("base.res_partner_12") |
| 12 | + cls.product = cls.env.ref("product.product_product_9") |
| 13 | + cls.product_packaging = cls.env["product.packaging"].create( |
| 14 | + { |
| 15 | + "name": "Box of 12", |
| 16 | + "qty": 12, |
| 17 | + "product_id": cls.product.id, |
| 18 | + } |
| 19 | + ) |
| 20 | + cls.order = cls.env["sale.order"].create( |
| 21 | + { |
| 22 | + "partner_id": cls.partner.id, |
| 23 | + "order_line": [ |
| 24 | + ( |
| 25 | + 0, |
| 26 | + 0, |
| 27 | + { |
| 28 | + "product_id": cls.product.id, |
| 29 | + "product_uom": cls.product.uom_id.id, |
| 30 | + "product_uom_qty": 24.0, |
| 31 | + "product_packaging_id": cls.product_packaging.id, |
| 32 | + "product_packaging_qty": 2, |
| 33 | + }, |
| 34 | + ) |
| 35 | + ], |
| 36 | + } |
| 37 | + ) |
| 38 | + |
| 39 | + def test_product_packaging_fields_in_report(self): |
| 40 | + self.order.action_confirm() |
| 41 | + |
| 42 | + select_fields = self.env["sale.report"]._select_additional_fields() |
| 43 | + group_by_fields = self.env["sale.report"]._group_by_sale() |
| 44 | + from_clause = self.env["sale.report"]._from_sale() |
| 45 | + |
| 46 | + self.assertIn( |
| 47 | + "product_packaging_id", |
| 48 | + select_fields, |
| 49 | + "'product_packaging_id' is not in the select fields.", |
| 50 | + ) |
| 51 | + self.assertIn( |
| 52 | + "product_packaging_qty", |
| 53 | + select_fields, |
| 54 | + "'product_packaging_qty' is not in the select fields.", |
| 55 | + ) |
| 56 | + self.assertIn( |
| 57 | + "product_packaging_qty_delivered", |
| 58 | + select_fields, |
| 59 | + "'product_packaging_qty_delivered' is not in the select fields.", |
| 60 | + ) |
| 61 | + |
| 62 | + self.assertIn( |
| 63 | + "l.product_packaging_id", |
| 64 | + group_by_fields, |
| 65 | + "'product_packaging_id' is not in the GROUP BY clause.", |
| 66 | + ) |
| 67 | + |
| 68 | + self.assertIn( |
| 69 | + "LEFT JOIN product_packaging", |
| 70 | + from_clause, |
| 71 | + "LEFT JOIN with 'product_packaging' is missing in the FROM clause.", |
| 72 | + ) |
| 73 | + |
| 74 | + def test_product_packaging_report_values(self): |
| 75 | + self.order.action_confirm() |
| 76 | + |
| 77 | + self.env.invalidate_all() |
| 78 | + sale_report = self.env["sale.report"].read_group( |
| 79 | + domain=[("order_reference", "=", f"sale.order,{self.order.id}")], |
| 80 | + fields=[ |
| 81 | + "product_packaging_id", |
| 82 | + "product_packaging_qty", |
| 83 | + "product_packaging_qty_delivered", |
| 84 | + ], |
| 85 | + groupby=["product_packaging_id"], |
| 86 | + ) |
| 87 | + |
| 88 | + self.assertTrue(sale_report, "No sale report entries found for the sale order.") |
| 89 | + |
| 90 | + report_entry = sale_report[0] |
| 91 | + self.assertEqual( |
| 92 | + report_entry["product_packaging_id"][0], |
| 93 | + self.product_packaging.id, |
| 94 | + "Incorrect product packaging in the report.", |
| 95 | + ) |
| 96 | + self.assertEqual( |
| 97 | + report_entry["product_packaging_qty"], |
| 98 | + 2, |
| 99 | + "Incorrect product packaging quantity in the report.", |
| 100 | + ) |
| 101 | + self.assertEqual( |
| 102 | + report_entry["product_packaging_qty_delivered"], |
| 103 | + 0, |
| 104 | + "Incorrect product packaging delivered quantity in the report.", |
| 105 | + ) |
0 commit comments