Debian Codegraph @

addons/pos_restaurant_loyalty/tests/test_pos_restaurant_loyalty.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.addons.pos_restaurant.tests.test_frontend import TestFrontend
4 from odoo.tests import tagged
5 from odoo import Command
6
7
8 @tagged("post_install", "-at_install")
9 class TestPoSRestaurantLoyalty(TestFrontend):
10 def test_change_table_rewards_stay(self):
11 """
12 Test that make sure that rewards stay on the order when leaving the table
13 """
14 self.env['loyalty.program'].create({
15 'name': 'My super program',
16 'program_type': 'promotion',
17 'trigger': 'auto',
18 'applies_on': 'current',
19 'rule_ids': [Command.create({
20 'minimum_qty': 1,
21 })],
22 'reward_ids': [Command.create({
23 'reward_type': 'discount',
24 'discount': 10,
25 'discount_mode': 'percent',
26 'discount_applicability': 'order',
27 })],
28 })
29 self.pos_config.with_user(self.pos_user).open_ui()
30 self.start_pos_tour("PosRestaurantRewardStay")
31 order = self.env['pos.order'].search([])
32 self.assertEqual(order.currency_id.round(order.amount_total), 1.98)
33
34 def test_loyalty_reward_with_courses(self):
35 """
36 Ensure that a loyalty reward line remains in the cart
37 when courses are applied in a restaurant POS order.
38 """
39 self.env['loyalty.program'].search([]).write({'active': False})
40 self.env['loyalty.program'].create({
41 'name': '10% Discount on All Products',
42 'program_type': 'promotion',
43 'trigger': 'auto',
44 'applies_on': 'current',
45 'rule_ids': [Command.create({
46 'minimum_qty': 1,
47 })],
48 'reward_ids': [Command.create({
49 'reward_type': 'discount',
50 'discount': 10,
51 'discount_mode': 'percent',
52 'discount_applicability': 'order',
53 })],
54 })
55 self.pos_config.with_user(self.pos_user).open_ui()
56 self.start_pos_tour('test_loyalty_reward_with_courses')
57 orders = self.pos_config.current_session_id.order_ids
58 self.assertEqual(len(orders), 2)
59 self.assertEqual(orders[0].currency_id.round(orders[0].amount_total), 1.98)
60 self.assertEqual(len(orders[0].lines.filtered(lambda line: line.is_reward_line)), 1)
61 self.assertEqual(orders[1].currency_id.round(orders[1].amount_total), 1.98)
62 self.assertEqual(len(orders[1].lines.filtered(lambda line: line.is_reward_line)), 1)