Debian Codegraph @

addons/point_of_sale/tests/test_pos_product_variants.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import Command
4 from odoo.tests import tagged
5
6 from odoo.addons.product.tests.common import ProductVariantsCommon
7 from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon
8
9
10 @tagged('post_install', '-at_install')
11 class TestPoSProductVariants(ProductVariantsCommon, TestPointOfSaleHttpCommon):
12
13 def test_integration_dynamic_variant_price(self):
14 """Tests the price of products with dynamic variant when added to cart"""
15 self.env['product.attribute.value'].create({
16 'name': 'dyn3',
17 'attribute_id': self.dynamic_attribute.id,
18 'default_extra_price': 10,
19 })
20 (dyn1, dyn2, dyn3) = self.dynamic_attribute.value_ids
21 dyn2.default_extra_price = 5
22
23 product_template = self.env['product.template'].create({
24 'name': 'A dynamic product',
25 'taxes_id': False,
26 'available_in_pos': True,
27 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
28 })
29 self.env['product.template.attribute.line'].create({
30 'product_tmpl_id': product_template.id,
31 'attribute_id': self.dynamic_attribute.id,
32 'value_ids': [Command.set([dyn1.id, dyn2.id, dyn3.id])],
33 })
34
35 # Create a variant (because of dynamic attribute)
36 ptav_dyn2 = self.env['product.template.attribute.value'].search([
37 ('attribute_line_id', '=', product_template.attribute_line_ids.id),
38 ('product_attribute_value_id', '=', dyn2.id)
39 ])
40
41 self.env['product.product'].create({
42 'available_in_pos': True,
43 'product_tmpl_id': product_template.id,
44 'product_template_attribute_value_ids': [(6, 0, [ptav_dyn2.id])],
45 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
46 })
47 self.main_pos_config.with_user(self.pos_user).open_ui()
48 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_dynamic_variant_price', login="pos_user")
49
50 def test_integration_always_variant_price(self):
51 """Tests the price of products with always variant when added to cart"""
52 self.size_attribute_m.default_extra_price = 5
53
54 product_template = self.env['product.template'].create({
55 'name': 'A always product',
56 'uom_id': self.env.ref('uom.product_uom_unit').id,
57 'is_storable': True,
58 'taxes_id': False,
59 'available_in_pos': True,
60 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
61 })
62 self.env['product.template.attribute.line'].create({
63 'product_tmpl_id': product_template.id,
64 'attribute_id': self.size_attribute.id,
65 'value_ids': [Command.set([self.size_attribute_s.id, self.size_attribute_m.id])],
66 })
67
68 self.main_pos_config.with_user(self.pos_user).open_ui()
69 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_always_variant_price', login="pos_user")
70
71 def test_integration_never_variant_price(self):
72 """Tests the price of products with no variant(never) variant when added to cart"""
73 self.no_variant_attribute_second.default_extra_price = 5
74
75 product_template = self.env['product.template'].create({
76 'name': 'A never product',
77 'uom_id': self.env.ref('uom.product_uom_unit').id,
78 'is_storable': True,
79 'taxes_id': False,
80 'available_in_pos': True,
81 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
82 })
83 self.env['product.template.attribute.line'].create({
84 'product_tmpl_id': product_template.id,
85 'attribute_id': self.no_variant_attribute.id,
86 'value_ids': [Command.set([self.no_variant_attribute_extra.id, self.no_variant_attribute_second.id])],
87 })
88
89 self.main_pos_config.with_user(self.pos_user).open_ui()
90 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_never_variant_price', login="pos_user")
91
92 def test_integration_dynamic_always_variant_price(self):
93 """Tests the price of products with dynamic and always variants when added to cart"""
94 self.env['product.attribute.value'].create({
95 'name': 'dyn3',
96 'attribute_id': self.dynamic_attribute.id,
97 'default_extra_price': 20,
98 })
99 (dyn1, dyn2, dyn3) = self.dynamic_attribute.value_ids
100 dyn2.default_extra_price = 10
101 self.size_attribute_m.default_extra_price = 5
102
103 product_template = self.env['product.template'].create({
104 'name': 'A dyn/alw product',
105 'taxes_id': False,
106 'available_in_pos': True,
107 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
108 })
109 self.env['product.template.attribute.line'].create([{
110 'product_tmpl_id': product_template.id,
111 'attribute_id': self.dynamic_attribute.id,
112 'value_ids': [Command.set([dyn1.id, dyn2.id, dyn3.id])],
113 }, {
114 'product_tmpl_id': product_template.id,
115 'attribute_id': self.size_attribute.id,
116 'value_ids': [Command.set([self.size_attribute_s.id, self.size_attribute_m.id])],
117 }])
118
119 # Create a variant (because of dynamic attribute)
120 ptav_dyn2 = self.env['product.template.attribute.value'].search([
121 ('attribute_line_id', '=', product_template.attribute_line_ids[0].id),
122 ('product_attribute_value_id', '=', dyn2.id)
123 ])
124 ptav_always1 = self.env['product.template.attribute.value'].search([
125 ('attribute_line_id', '=', product_template.attribute_line_ids[1].id),
126 ('product_attribute_value_id', '=', self.size_attribute_s.id)
127 ])
128
129 self.env['product.product'].create({
130 'available_in_pos': True,
131 'product_tmpl_id': product_template.id,
132 'product_template_attribute_value_ids': [(6, 0, (ptav_dyn2 + ptav_always1).ids)],
133 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
134 })
135 self.main_pos_config.with_user(self.pos_user).open_ui()
136 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_dynamic_always_variant_price', login="pos_user")
137
138 def test_integration_dynamic_never_variant_price(self):
139 """Tests the price of products with dynamic and never variants when added to cart"""
140 self.env['product.attribute.value'].create({
141 'name': 'dyn3',
142 'attribute_id': self.dynamic_attribute.id,
143 'default_extra_price': 20,
144 })
145 (dyn1, dyn2, dyn3) = self.dynamic_attribute.value_ids
146 dyn2.default_extra_price = 10
147 self.no_variant_attribute_second.default_extra_price = 5
148
149 product_template = self.env['product.template'].create({
150 'name': 'A dyn/nev product',
151 'taxes_id': False,
152 'available_in_pos': True,
153 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
154 })
155 self.env['product.template.attribute.line'].create([{
156 'product_tmpl_id': product_template.id,
157 'attribute_id': self.dynamic_attribute.id,
158 'value_ids': [Command.set([dyn1.id, dyn2.id, dyn3.id])],
159 }, {
160 'product_tmpl_id': product_template.id,
161 'attribute_id': self.no_variant_attribute.id,
162 'value_ids': [Command.set([self.no_variant_attribute_extra.id, self.no_variant_attribute_second.id])],
163 }])
164
165 # Create a variant (because of dynamic attribute)
166 ptav_dyn2 = self.env['product.template.attribute.value'].search([
167 ('attribute_line_id', '=', product_template.attribute_line_ids[0].id),
168 ('product_attribute_value_id', '=', dyn2.id)
169 ])
170 ptav_never1 = self.env['product.template.attribute.value'].search([
171 ('attribute_line_id', '=', product_template.attribute_line_ids[1].id),
172 ('product_attribute_value_id', '=', self.no_variant_attribute_extra.id)
173 ])
174
175 self.env['product.product'].create({
176 'available_in_pos': True,
177 'product_tmpl_id': product_template.id,
178 'product_template_attribute_value_ids': [(6, 0, (ptav_dyn2 + ptav_never1).ids)],
179 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
180 })
181 self.main_pos_config.with_user(self.pos_user).open_ui()
182 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_dynamic_never_variant_price', login="pos_user")
183
184 def test_integration_always_never_variant_price(self):
185 """Tests the price of products with always and never variants when added to cart"""
186 self.no_variant_attribute_second.default_extra_price = 5
187 self.size_attribute_m.default_extra_price = 10
188
189 product_template = self.env['product.template'].create({
190 'name': 'A alw/nev product',
191 'uom_id': self.env.ref('uom.product_uom_unit').id,
192 'is_storable': True,
193 'taxes_id': False,
194 'available_in_pos': True,
195 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
196 })
197 self.env['product.template.attribute.line'].create([{
198 'product_tmpl_id': product_template.id,
199 'attribute_id': self.no_variant_attribute.id,
200 'value_ids': [Command.set([self.no_variant_attribute_extra.id, self.no_variant_attribute_second.id])],
201 }, {
202 'product_tmpl_id': product_template.id,
203 'attribute_id': self.size_attribute.id,
204 'value_ids': [Command.set([self.size_attribute_s.id, self.size_attribute_m.id])],
205 }])
206
207 self.main_pos_config.with_user(self.pos_user).open_ui()
208 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_always_never_variant_price', login="pos_user")
209
210 def test_integration_dynamic_always_never_variant_price(self):
211 """Tests the price of products with all types of variants when added to cart"""
212 (dyn1, dyn2) = self.dynamic_attribute.value_ids
213 dyn2.default_extra_price = 10
214 self.size_attribute_m.default_extra_price = 5
215 self.no_variant_attribute_second.default_extra_price = 0.5
216
217 product_template = self.env['product.template'].create({
218 'name': 'A dyn/alw/nev product',
219 'taxes_id': False,
220 'available_in_pos': True,
221 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
222 })
223 self.env['product.template.attribute.line'].create([{
224 'product_tmpl_id': product_template.id,
225 'attribute_id': self.dynamic_attribute.id,
226 'value_ids': [Command.set([dyn1.id, dyn2.id])],
227 }, {
228 'product_tmpl_id': product_template.id,
229 'attribute_id': self.no_variant_attribute.id,
230 'value_ids': [Command.set([self.no_variant_attribute_extra.id, self.no_variant_attribute_second.id])],
231 }, {
232 'product_tmpl_id': product_template.id,
233 'attribute_id': self.size_attribute.id,
234 'value_ids': [Command.set([self.size_attribute_s.id, self.size_attribute_m.id])],
235 }])
236
237 # Create a variant (because of dynamic attribute)
238 ptav_dyn2 = self.env['product.template.attribute.value'].search([
239 ('attribute_line_id', '=', product_template.attribute_line_ids[0].id),
240 ('product_attribute_value_id', '=', dyn2.id)
241 ])
242 ptav_never1 = self.env['product.template.attribute.value'].search([
243 ('attribute_line_id', '=', product_template.attribute_line_ids[1].id),
244 ('product_attribute_value_id', '=', self.no_variant_attribute_extra.id)
245 ])
246 ptav_always1 = self.env['product.template.attribute.value'].search([
247 ('attribute_line_id', '=', product_template.attribute_line_ids[1].id),
248 ('product_attribute_value_id', '=', self.size_attribute_s.id)
249 ])
250
251 self.env['product.product'].create({
252 'available_in_pos': True,
253 'product_tmpl_id': product_template.id,
254 'product_template_attribute_value_ids': [(6, 0, (ptav_dyn2 + ptav_always1 + ptav_never1).ids)],
255 'pos_categ_ids': [Command.set(self.pos_desk_misc_test.ids)],
256 })
257 self.main_pos_config.with_user(self.pos_user).open_ui()
258 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_integration_dynamic_always_never_variant_price', login="pos_user")
259
260 def test_image_variants_displayed(self):
261 """
262 Tests that the user can correctly chose variants in the product_configurator_popup
263 if the variant was set as Image
264 """
265 image_attribute = self.env['product.attribute'].create({
266 'name': 'Images',
267 'display_type': 'image',
268 'create_variant': 'always',
269 })
270 images = self.env['product.attribute.value'].create([{
271 'name': 'First Image',
272 'attribute_id': image_attribute.id,
273 }, {
274 'name': 'Second Image',
275 'attribute_id': image_attribute.id,
276 'default_extra_price': 20,
277 }])
278 product_template = self.env['product.template'].create({
279 'name': 'Image Product',
280 'is_storable': True,
281 'taxes_id': False,
282 'available_in_pos': True,
283 })
284 self.env['product.template.attribute.line'].create({
285 'product_tmpl_id': product_template.id,
286 'attribute_id': image_attribute.id,
287 'value_ids': [Command.set([images[0].id, images[1].id])],
288 })
289
290 self.main_pos_config.with_user(self.pos_user).open_ui()
291 self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'test_image_variants_displayed', login="pos_user")