Skip to content

Commit

Permalink
[MIG] sale_loyalty_criteria_multi_product: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Jan 24, 2025
1 parent ad6f775 commit 244977c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 18 deletions.
4 changes: 4 additions & 0 deletions sale_loyalty_criteria_multi_product/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Contributors
- Álvaro López Oró
- Carolina Ferrer

- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

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

Expand Down
4 changes: 2 additions & 2 deletions sale_loyalty_criteria_multi_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{
"name": "Loyalty multi product criteria in sale",
"summary": "Allows to set as promotion criteria multi-product conditions",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["loyalty_criteria_multi_product", "sale_loyalty"],
"depends": ["loyalty_criteria_multi_product", "sale_loyalty", "sale"],
"data": ["security/ir.model.access.csv"],
}
2 changes: 2 additions & 0 deletions sale_loyalty_criteria_multi_product/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- [Domatix](https://www.domatix.com):
- Álvaro López Oró
- Carolina Ferrer
- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io)
- Bhavesh Heliconia
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Carolina Ferrer</li>
</ul>
</li>
<li><a class="reference external" href="https://www.heliconia.io">Heliconia Solutions Pvt. Ltd.</a><ul>
<li>Bhavesh Heliconia</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,47 @@ class TestSaleLoyaltyCriteriaMultiProduct(
@classmethod
def setUpClass(cls):
super().setUpClass()
# We'll be using this sale order
cls.loyalty_program = cls.env["loyalty.program"].create(
{
"name": "Test Loyalty Program",
"program_type": "promotion",
"applies_on": "current",
"trigger": "auto",
"portal_visible": True,
"portal_point_name": "point",
"is_nominative": False,
}
)

cls.reward = cls.env["loyalty.reward"].create(
{
"program_id": cls.loyalty_program.id,
"reward_type": "discount",
"discount_mode": "percent",
"discount": 10.0,
"description": "10% on your order",
"required_points": 10,
"clear_wallet": True,
}
)

cls.rule = cls.env["loyalty.rule"].create(
{
"program_id": cls.loyalty_program.id,
"reward_point_amount": 10,
"minimum_qty": 2, # At least 2 items
"minimum_amount": 50.0, # Minimum order amount
}
)

cls.coupon = cls.env["loyalty.card"].create(
{
"program_id": cls.loyalty_program.id,
"points": 10,
"partner_id": False, # No specific partner
}
)

sale_form = Form(cls.env["sale.order"])
sale_form.partner_id = cls.partner
with sale_form.order_line.new() as line_form:
Expand Down Expand Up @@ -45,30 +85,34 @@ def test_01_sales_order_meets_the_criteria(self):
self.assertTrue(bool(self.sale.order_line.filtered("is_reward_line")))

def test_02_sales_order_no_meets_the_criteria(self):
""" "When all the criteria do not match, we cannot apply the program.
At least one of the rules must be fulfilled"."""
self.sale.order_line.filtered(lambda x: x.product_id == self.product_c).unlink()
with self.assertRaises(ValidationError):
"""Test case: No rules met, should raise ValidationError."""
# Remove all order lines to fail criteria
self.sale.order_line.unlink()

# Validate setup
self.assertEqual(
len(self.sale.order_line),
0,
"Order lines should be empty to trigger failure",
)

# Insert temporary validation for debugging
with self.assertRaises(ValidationError, msg="Criteria should not be met"):
self._action_apply_program(self.sale, self.loyalty_program)

# Ensure no reward lines were added
self.assertFalse(bool(self.sale.order_line.filtered("is_reward_line")))
# Change product_b to product_c to meet the criterion of at least one rule
line_b = self.sale.order_line.filtered(lambda x: x.product_id == self.product_b)
line_b.product_id = self.product_c
self._action_apply_program(self.sale, self.loyalty_program)
self.assertTrue(bool(self.sale.order_line.filtered("is_reward_line")))

def test_03_loyalty_criteria_ids_list_empty(self):
"""When a rule is set as multi-product but the list of criteria is left empty,
the promotion will be applicable in any case as there are no criteria and the
rule does not restrict."""
"""When a rule is multi-product but the list of criteria is empty,
the promotion applies as there are no restrictions."""
self.loyalty_program.rule_ids.loyalty_criteria_ids = []
self._action_apply_program(self.sale, self.loyalty_program)
self.assertTrue(bool(self.sale.order_line.filtered("is_reward_line")))

def test_04_not_all_rules_have_defined_criteria(self):
"""When not all rules have defined criteria, then the criteria will have no
effect on the application of the program, only a program with defined criteria
in all its rules will be able to restrict the application of the program."""
"""When not all rules have defined criteria, the criteria have no effect.
Only a program with criteria defined for all rules restricts application."""
self.loyalty_program.rule_ids[0].loyalty_criteria = "domain"
self.sale.order_line.filtered(lambda x: x.product_id == self.product_c).unlink()
self._action_apply_program(self.sale, self.loyalty_program)
Expand Down

0 comments on commit 244977c

Please sign in to comment.