Skip to content

Commit

Permalink
[MIG] sale_loyalty_partner: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Jan 23, 2025
1 parent ea5d2b1 commit 37649be
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sale_loyalty_partner/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Contributors
- Carlos Roca
- Pilar Vargas

- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion sale_loyalty_partner/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Sale Loyalty Partner",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-promotion",
"license": "AGPL-3",
Expand Down
1 change: 1 addition & 0 deletions sale_loyalty_partner/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
- Pedro M. Baeza
- Carlos Roca
- Pilar Vargas
- [Heliconia Solutions Pvt. Ltd.\](<https://www.heliconia.io>)
1 change: 1 addition & 0 deletions sale_loyalty_partner/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Pilar Vargas</li>
</ul>
</li>
<li>[Heliconia Solutions Pvt. Ltd.](<a class="reference external" href="https://www.heliconia.io">https://www.heliconia.io</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
1 change: 1 addition & 0 deletions sale_loyalty_partner/tests/__init__.py
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 sale_loyalty_partner/tests/test_sale_loyalty_loyalty_program.py
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",
)

0 comments on commit 37649be

Please sign in to comment.