Skip to content

Commit

Permalink
[FIX] website_sale_loyalty: ewallet application fix
Browse files Browse the repository at this point in the history
Due to 994ee3f commit, ewallet could no
longer be applied.
  • Loading branch information
anko-odoo committed Mar 26, 2024
1 parent 60dc7d7 commit d875e98
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion addons/website_sale_loyalty/controllers/main.py
Expand Up @@ -92,7 +92,9 @@ def claim_reward(self, reward_id, code=None, **post):
coupon = coupon_
if code == coupon.code and (
(program_sudo.trigger == 'with_code' and program_sudo.program_type != 'promo_code')
or (program_sudo.trigger == 'auto' and program_sudo.applies_on == 'future')
or (program_sudo.trigger == 'auto'
and program_sudo.applies_on == 'future'
and program_sudo.program_type not in ('ewallet', 'loyalty'))
):
return self.pricelist(code)
if coupon:
Expand Down
1 change: 1 addition & 0 deletions addons/website_sale_loyalty/tests/__init__.py
Expand Up @@ -5,3 +5,4 @@
from . import test_shop_sale_coupon
from . import test_website_sale_loyalty_delivery
from . import test_free_product_reward
from . import test_ewallet
61 changes: 61 additions & 0 deletions addons/website_sale_loyalty/tests/test_ewallet.py
@@ -0,0 +1,61 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import http, Command
from odoo.tests import tagged, HttpCase
from odoo.addons.website.tools import MockRequest
from odoo.addons.website_sale_loyalty.controllers.main import WebsiteSale
from odoo.addons.website_sale.tests.common import WebsiteSaleCommon

@tagged('post_install', '-at_install')
class TestEwallet(HttpCase, WebsiteSaleCommon):

@classmethod
def setUpClass(cls):
super().setUpClass()

cls.WebsiteSaleController = WebsiteSale()
cls.website = cls.env['website'].browse(1)

cls.topup = cls.env['product.product'].create({
'name': 'Ewallet Top up',
'list_price': 50.0,
'website_published': True,
})

cls.ewallet_program = cls.env['loyalty.program'].create([{
'name': 'E-wallet Card Program',
'program_type': 'ewallet',
'trigger': 'auto',
'applies_on': 'future',
'rule_ids': [Command.create({
'reward_point_mode': 'money',
'reward_point_amount': 10,
'product_ids': cls.topup,
})],
'reward_ids': [Command.create({
'discount_mode': 'per_point',
'discount': 1,
'discount_applicability': 'order',
})],
}])
installed_modules = set(cls.env['ir.module.module'].search([
('state', '=', 'installed'),
]).mapped('name'))
for _ in http._generate_routing_rules(installed_modules, nodb_only=False):
pass

def test_ewallet(self):
self.env['loyalty.generate.wizard'].create({
'program_id': self.ewallet_program.id,
'coupon_qty': 1,
'points_granted': 10,
}).generate_coupons()

self.ewallet_program.coupon_ids[0].partner_id = self.env.user.partner_id

order = self.empty_cart
with MockRequest(self.env, website=self.website, sale_order_id=order.id):
self.WebsiteSaleController.cart_update_json(self.consumable_product.id, set_qty=1)
self.assertEqual(order.amount_total, 20)
self.WebsiteSaleController.claim_reward(self.ewallet_program.reward_ids[0].id)
self.assertEqual(order.amount_total, 10)

0 comments on commit d875e98

Please sign in to comment.