| 1 |
|
| 2 |
|
| 3 |
from odoo import http |
| 4 |
from odoo.fields import Command |
| 5 |
from odoo.tests import HttpCase, tagged |
| 6 |
|
| 7 |
from odoo.addons.website_sale.tests.common import MockRequest, WebsiteSaleCommon |
| 8 |
from odoo.addons.website_sale_loyalty.controllers.cart import Cart |
| 9 |
from odoo.addons.website_sale_loyalty.controllers.main import WebsiteSale |
| 10 |
|
| 11 |
|
| 12 |
@tagged('post_install', '-at_install') |
| 13 |
class TestEwallet(HttpCase, WebsiteSaleCommon): |
| 14 |
|
| 15 |
@classmethod |
| 16 |
def setUpClass(cls): |
| 17 |
super().setUpClass() |
| 18 |
|
| 19 |
cls.WebsiteSaleController = WebsiteSale() |
| 20 |
cls.WebsiteSaleCartController = Cart() |
| 21 |
|
| 22 |
cls.product.write({'taxes_id': [Command.clear()]}) |
| 23 |
|
| 24 |
cls.topup = cls.env['product.product'].create({ |
| 25 |
'name': 'Ewallet Top up', |
| 26 |
'list_price': 50.0, |
| 27 |
'website_published': True, |
| 28 |
}) |
| 29 |
|
| 30 |
cls.ewallet_program = cls.env['loyalty.program'].create([{ |
| 31 |
'name': 'E-wallet Card Program', |
| 32 |
'program_type': 'ewallet', |
| 33 |
'trigger': 'auto', |
| 34 |
'applies_on': 'future', |
| 35 |
'rule_ids': [Command.create({ |
| 36 |
'reward_point_mode': 'money', |
| 37 |
'reward_point_amount': 10, |
| 38 |
'product_ids': cls.topup, |
| 39 |
})], |
| 40 |
'reward_ids': [Command.create({ |
| 41 |
'discount_mode': 'per_point', |
| 42 |
'discount': 1, |
| 43 |
'discount_applicability': 'order', |
| 44 |
})], |
| 45 |
}]) |
| 46 |
installed_modules = set(cls.env['ir.module.module'].search([ |
| 47 |
('state', '=', 'installed'), |
| 48 |
]).mapped('name')) |
| 49 |
for _ in http._generate_routing_rules(installed_modules, nodb_only=False): |
| 50 |
pass |
| 51 |
|
| 52 |
def test_ewallet(self): |
| 53 |
self.env['loyalty.generate.wizard'].create({ |
| 54 |
'program_id': self.ewallet_program.id, |
| 55 |
'coupon_qty': 1, |
| 56 |
'points_granted': 10, |
| 57 |
}).generate_coupons() |
| 58 |
|
| 59 |
self.ewallet_program.coupon_ids[0].partner_id = self.env.user.partner_id |
| 60 |
|
| 61 |
order = self.empty_cart |
| 62 |
with MockRequest(self.env, website=self.website, sale_order_id=order.id): |
| 63 |
self.WebsiteSaleCartController.add_to_cart( |
| 64 |
product_template_id=self.product.product_tmpl_id, |
| 65 |
product_id=self.product.id, |
| 66 |
quantity=1, |
| 67 |
) |
| 68 |
self.assertEqual(order.amount_total, 20) |
| 69 |
self.WebsiteSaleController.claim_reward(self.ewallet_program.reward_ids[0].id) |
| 70 |
self.assertEqual(order.amount_total, 10) |