-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] sale_packaging_report: Migration to 17.0
- Loading branch information
1 parent
4b6e518
commit c77f55a
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Jairo Llopis ([Moduon](https://www.moduon.team/)) | ||
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_sale_packaging_report |
105 changes: 105 additions & 0 deletions
105
sale_packaging_report/tests/test_sale_packaging_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright 2023 Moduon Team S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
from odoo.tests import TransactionCase | ||
|
||
|
||
class TestSaleReportPackaging(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.partner = cls.env.ref("base.res_partner_12") | ||
cls.product = cls.env.ref("product.product_product_9") | ||
cls.product_packaging = cls.env["product.packaging"].create( | ||
{ | ||
"name": "Box of 12", | ||
"qty": 12, | ||
"product_id": cls.product.id, | ||
} | ||
) | ||
cls.order = cls.env["sale.order"].create( | ||
{ | ||
"partner_id": cls.partner.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": cls.product.id, | ||
"product_uom": cls.product.uom_id.id, | ||
"product_uom_qty": 24.0, | ||
"product_packaging_id": cls.product_packaging.id, | ||
"product_packaging_qty": 2, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
|
||
def test_product_packaging_fields_in_report(self): | ||
self.order.action_confirm() | ||
|
||
select_fields = self.env["sale.report"]._select_additional_fields() | ||
group_by_fields = self.env["sale.report"]._group_by_sale() | ||
from_clause = self.env["sale.report"]._from_sale() | ||
|
||
self.assertIn( | ||
"product_packaging_id", | ||
select_fields, | ||
"'product_packaging_id' is not in the select fields.", | ||
) | ||
self.assertIn( | ||
"product_packaging_qty", | ||
select_fields, | ||
"'product_packaging_qty' is not in the select fields.", | ||
) | ||
self.assertIn( | ||
"product_packaging_qty_delivered", | ||
select_fields, | ||
"'product_packaging_qty_delivered' is not in the select fields.", | ||
) | ||
|
||
self.assertIn( | ||
"l.product_packaging_id", | ||
group_by_fields, | ||
"'product_packaging_id' is not in the GROUP BY clause.", | ||
) | ||
|
||
self.assertIn( | ||
"LEFT JOIN product_packaging", | ||
from_clause, | ||
"LEFT JOIN with 'product_packaging' is missing in the FROM clause.", | ||
) | ||
|
||
def test_product_packaging_report_values(self): | ||
self.order.action_confirm() | ||
|
||
self.env.invalidate_all() | ||
sale_report = self.env["sale.report"].read_group( | ||
domain=[("order_reference", "=", f"sale.order,{self.order.id}")], | ||
fields=[ | ||
"product_packaging_id", | ||
"product_packaging_qty", | ||
"product_packaging_qty_delivered", | ||
], | ||
groupby=["product_packaging_id"], | ||
) | ||
|
||
self.assertTrue(sale_report, "No sale report entries found for the sale order.") | ||
|
||
report_entry = sale_report[0] | ||
self.assertEqual( | ||
report_entry["product_packaging_id"][0], | ||
self.product_packaging.id, | ||
"Incorrect product packaging in the report.", | ||
) | ||
self.assertEqual( | ||
report_entry["product_packaging_qty"], | ||
2, | ||
"Incorrect product packaging quantity in the report.", | ||
) | ||
self.assertEqual( | ||
report_entry["product_packaging_qty_delivered"], | ||
0, | ||
"Incorrect product packaging delivered quantity in the report.", | ||
) |