Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] website_sale_loyalty: ewallet application fix #159356

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Expand Up @@ -42,7 +42,7 @@
<div class="flex-grow-1">
<t t-set="program" t-value="reward.program_id"/>
<t t-set="points" t-value="coupon._format_points(website_sale_order._get_real_points_for_coupon(coupon))"/>
<t t-if="program.program_type not in ['ewallet', 'promo_code'] and (program.trigger == 'with_code' or (program.trigger == 'auto' and program.applies_on == 'future'))">
<t t-if="program.program_type not in ['ewallet', 'promo_code', 'loyalty'] and (program.trigger == 'with_code' or (program.trigger == 'auto' and program.applies_on == 'future'))">
<t t-if="program.program_type == 'gift_card'">
anko-odoo marked this conversation as resolved.
Show resolved Hide resolved
<strong t-esc="reward.description"/>
<strong> - </strong>
Expand Down