-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] sale_loyalty_partner: Migration to 17.0
- Loading branch information
1 parent
ea5d2b1
commit 37649be
Showing
6 changed files
with
133 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
- Pedro M. Baeza | ||
- Carlos Roca | ||
- Pilar Vargas | ||
- [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_loyalty_loyalty_program |
127 changes: 127 additions & 0 deletions
127
sale_loyalty_partner/tests/test_sale_loyalty_loyalty_program.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,127 @@ | ||
# Copyright 2024 | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests import TransactionCase | ||
|
||
|
||
class TestLoyaltyProgramPartner(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
# Create test partner | ||
self.partner = self.env["res.partner"].create( | ||
{ | ||
"name": "Test Partner", | ||
"email": "[email protected]", | ||
} | ||
) | ||
|
||
# Create loyalty program | ||
self.loyalty_program = self.env["loyalty.program"].create( | ||
{ | ||
"name": "Test Loyalty Program", | ||
"partner_id": self.partner.id, | ||
"program_type": "promotion", | ||
"applies_on": "current", | ||
"trigger": "auto", | ||
} | ||
) | ||
|
||
# Create coupon linked to loyalty program | ||
self.program_coupon = self.env["loyalty.card"].create( | ||
{ | ||
"program_id": self.loyalty_program.id, | ||
"partner_id": self.partner.id, | ||
"points": 10, | ||
} | ||
) | ||
|
||
# Create test product | ||
self.product = self.env["product.product"].create( | ||
{ | ||
"name": "Test Product", | ||
"type": "consu", | ||
"list_price": 100.0, | ||
} | ||
) | ||
|
||
# Create sale order | ||
self.sale_order = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
} | ||
) | ||
self.env["sale.order.line"].create( | ||
{ | ||
"order_id": self.sale_order.id, | ||
"product_id": self.product.id, | ||
"product_uom_qty": 1, | ||
"price_unit": 100.0, | ||
} | ||
) | ||
|
||
# Apply coupon to the sale order | ||
self.sale_order.write({"applied_coupon_ids": [(4, self.program_coupon.id)]}) | ||
|
||
def _get_sale_report_data(self, sale_order): | ||
"""Helper method to get sale report data after ensuring it's up to date.""" | ||
self.env.flush_all() | ||
self.env.invalidate_all() | ||
|
||
return self.env["sale.report"].search( | ||
[ | ||
("name", "=", sale_order.name), | ||
("partner_id", "=", sale_order.partner_id.id), | ||
] | ||
) | ||
|
||
def test_loyalty_program_partner(self): | ||
"""Test that the loyalty program partner is set correctly.""" | ||
self.assertEqual( | ||
self.loyalty_program.partner_id, | ||
self.partner, | ||
"Partner should be correctly set on loyalty program", | ||
) | ||
|
||
def test_sale_report_includes_coupon(self): | ||
"""Test that the sale report includes applied coupon data.""" | ||
# Confirm sale order | ||
self.sale_order.action_confirm() | ||
|
||
# Get sale report data | ||
report_data = self._get_sale_report_data(self.sale_order) | ||
|
||
self.assertTrue(report_data, "Sale report data should be created") | ||
self.assertIn( | ||
self.program_coupon.id, | ||
self.sale_order.applied_coupon_ids.ids, | ||
"Coupon should be applied to the sale order", | ||
) | ||
|
||
def test_sale_report_no_coupon(self): | ||
"""Test sale report when no coupon is applied.""" | ||
# Create another sale order without a coupon | ||
sale_order = self.env["sale.order"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
} | ||
) | ||
self.env["sale.order.line"].create( | ||
{ | ||
"order_id": sale_order.id, | ||
"product_id": self.product.id, | ||
"product_uom_qty": 1, | ||
"price_unit": 100.0, | ||
} | ||
) | ||
|
||
# Confirm sale order | ||
sale_order.action_confirm() | ||
|
||
# Get sale report data | ||
report_data = self._get_sale_report_data(sale_order) | ||
|
||
self.assertTrue(report_data, "Sale report data should be created") | ||
self.assertFalse( | ||
sale_order.applied_coupon_ids, | ||
"No coupon should be applied to the sale order", | ||
) |