Debian Codegraph @

addons/website_sale_slides/tests/test_course_purchase_flow.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo.addons.website_slides.tests import common
5 from odoo.tests.common import users
6
7
8 class TestCoursePurchaseFlow(common.SlidesCase):
9 @classmethod
10 def setUpClass(cls):
11 super().setUpClass()
12 cls.user_salesman = cls.env['res.users'].create({
13 'name': 'salesman',
14 'login': 'salesman',
15 'email': '[email protected]',
16 'group_ids': [(6, 0, cls.env.ref('sales_team.group_sale_salesman').ids)],
17 })
18
19 cls.course_product = cls.env['product.product'].create({
20 'name': "Course Product",
21 'standard_price': 100,
22 'list_price': 150,
23 'type': 'service',
24 'invoice_policy': 'order',
25 'is_published': True,
26 })
27
28 def test_course_purchase_flow(self):
29 # Step1: assign a course product to 2 slide.channels
30 self.channel.write({
31 'enroll': 'payment',
32 'product_id': self.course_product.id
33 })
34
35 self.channel_2 = self.env['slide.channel'].with_user(self.user_officer).create({
36 'name': 'Test Channel',
37 'enroll': 'payment',
38 'product_id': self.course_product.id,
39 'is_published': True,
40 })
41
42 # Step 2: create a sale_order with the course product
43 sale_order = self.env['sale.order'].create({
44 'partner_id': self.customer.id,
45 'order_line': [
46 (0, 0, {
47 'name': self.course_product.name,
48 'product_id': self.course_product.id,
49 'product_uom_qty': 1,
50 'price_unit': self.course_product.list_price,
51 })
52 ],
53 })
54
55 sale_order.action_confirm()
56
57 # Step 3: check that the customer is now a member of both channel
58 self.assertIn(self.customer, self.channel.partner_ids)
59 self.assertIn(self.customer, self.channel_2.partner_ids)
60
61 # Step 4: Same test as salesman
62 salesman_sale_order = self.env['sale.order'].with_user(self.user_salesman).create({
63 'partner_id': self.user_portal.partner_id.id,
64 'order_line': [
65 (0, 0, {
66 'name': self.course_product.name,
67 'product_id': self.course_product.id,
68 'product_uom_qty': 1,
69 'price_unit': self.course_product.list_price,
70 })
71 ],
72 })
73
74 salesman_sale_order.action_confirm()
75
76 self.assertIn(self.user_portal.partner_id, self.channel.partner_ids)
77 self.assertIn(self.user_portal.partner_id, self.channel_2.partner_ids)
78
79 @users('user_officer')
80 def test_course_product_published_synch(self):
81 """ Test the synchronization between a course and its product """
82 course_1 = self.env['slide.channel'].create({
83 'name': 'Test Channel 1',
84 'enroll': 'payment',
85 'product_id': self.course_product.id,
86 })
87 course_2 = self.env['slide.channel'].create({
88 'name': 'Test Channel 2',
89 'enroll': 'payment',
90 'product_id': self.course_product.id,
91 'is_published': True,
92 })
93
94 # The course_1 is not published by default which doesn't impact the product
95 self.assertFalse(course_1.is_published)
96 self.assertTrue(self.course_product.is_published)
97
98 course_1.is_published = True
99
100 # The course_1 and the product are published
101 self.assertTrue(course_1.is_published)
102 self.assertTrue(self.course_product.is_published)
103
104 self.course_product.is_published = False
105
106 # Unpublishing the product should not change the course_1
107 self.assertTrue(course_1.is_published)
108 self.assertFalse(self.course_product.is_published)
109
110 course_1.is_published = False
111
112 self.assertFalse(course_1.is_published)
113 self.assertFalse(self.course_product.is_published)
114
115 course_1.is_published = True
116
117 # Publishing the course_1 should publish the product
118 self.assertTrue(course_1.is_published)
119 self.assertTrue(self.course_product.is_published)
120
121 (course_1 + course_2).write({'is_published': False})
122
123 # If all course linked to a product are unpublished, we unpublished the product
124 self.assertFalse(course_1.is_published)
125 self.assertFalse(course_2.is_published)
126 self.assertFalse(self.course_product.is_published)