Debian Codegraph @

addons/point_of_sale/tests/common_setup_methods.py

raw
1 from odoo.fields import Command
2
3
4 def setup_product_combo_items(self):
5 tax10 = self.env["account.tax"].create(
6 {
7 "name": "10%",
8 "amount": 10,
9 "amount_type": "percent",
10 "type_tax_use": "sale",
11 }
12 )
13 tax20in = self.env["account.tax"].create(
14 {
15 "name": "20% incl",
16 "amount": 20,
17 "amount_type": "percent",
18 "type_tax_use": "sale",
19 "price_include_override": "tax_included",
20 "include_base_amount": True,
21 }
22 )
23 tax30 = self.env["account.tax"].create(
24 {
25 "name": "30%",
26 "amount": 30,
27 "amount_type": "percent",
28 "type_tax_use": "sale",
29 }
30 )
31
32 pos_category_1 = self.env["pos.category"].create({
33 "name": "Category 1",
34 })
35 pos_category_2 = self.env["pos.category"].create({
36 "name": "Category 2",
37 })
38 pos_category_3 = self.env["pos.category"].create({
39 "name": "Category 3",
40 })
41
42 combo_product_1 = self.env["product.product"].create(
43 {
44 "name": "Combo Product 1",
45 "is_storable": True,
46 "available_in_pos": True,
47 "list_price": 10,
48 "taxes_id": [(6, 0, [tax10.id])],
49 "pos_categ_ids": [(6, 0, [pos_category_1.id])],
50 }
51 )
52
53 combo_product_2 = self.env["product.product"].create(
54 {
55 "name": "Combo Product 2",
56 "is_storable": True,
57 "available_in_pos": True,
58 "list_price": 11,
59 "taxes_id": [(6, 0, [tax20in.id])],
60 "pos_categ_ids": [(6, 0, [pos_category_1.id])],
61 }
62 )
63
64 combo_product_3 = self.env["product.product"].create(
65 {
66 "name": "Combo Product 3",
67 "is_storable": True,
68 "available_in_pos": True,
69 "list_price": 16,
70 "taxes_id": [(6, 0, [tax30.id])],
71 "pos_categ_ids": [(6, 0, [pos_category_1.id])],
72 }
73 )
74
75 self.desk_accessories_combo = self.env["product.combo"].create(
76 {
77 "name": "Desk Accessories Combo",
78 "combo_item_ids": [
79 Command.create({
80 "product_id": combo_product_1.id,
81 "extra_price": 0,
82 }),
83 Command.create({
84 "product_id": combo_product_2.id,
85 "extra_price": 0,
86 }),
87 Command.create({
88 "product_id": combo_product_3.id,
89 "extra_price": 2,
90 }),
91 ],
92 }
93 )
94
95 combo_product_4 = self.env["product.product"].create(
96 {
97 "name": "Combo Product 4",
98 "is_storable": True,
99 "available_in_pos": True,
100 "list_price": 20,
101 "taxes_id": [(6, 0, [tax10.id])],
102 "pos_categ_ids": [(6, 0, [pos_category_2.id])],
103 }
104 )
105
106 combo_product_5 = self.env["product.product"].create(
107 {
108 "name": "Combo Product 5",
109 "is_storable": True,
110 "available_in_pos": True,
111 "list_price": 25,
112 "taxes_id": [(6, 0, [tax20in.id])],
113 "pos_categ_ids": [(6, 0, [pos_category_2.id])],
114 }
115 )
116
117 self.desks_combo = self.env["product.combo"].create(
118 {
119 "name": "Desks Combo",
120 "combo_item_ids": [
121 Command.create({
122 "product_id": combo_product_4.id,
123 "extra_price": 0,
124 }),
125 Command.create({
126 "product_id": combo_product_5.id,
127 "extra_price": 2,
128 }),
129 ],
130 }
131 )
132
133 combo_product_6 = self.env["product.product"].create(
134 {
135 "name": "Combo Product 6",
136 "is_storable": True,
137 "available_in_pos": True,
138 "list_price": 30,
139 "taxes_id": [(6, 0, [tax30.id])],
140 "pos_categ_ids": [(6, 0, [pos_category_3.id])],
141 }
142 )
143
144 combo_product_7 = self.env["product.product"].create(
145 {
146 "name": "Combo Product 7",
147 "is_storable": True,
148 "available_in_pos": True,
149 "list_price": 32,
150 "taxes_id": [(6, 0, [tax10.id])],
151 "pos_categ_ids": [(6, 0, [pos_category_3.id])],
152 }
153 )
154
155 combo_product_8 = self.env["product.product"].create(
156 {
157 "name": "Combo Product 8",
158 "is_storable": True,
159 "available_in_pos": True,
160 "list_price": 40,
161 "taxes_id": [(6, 0, [tax20in.id])],
162 "pos_categ_ids": [(6, 0, [pos_category_3.id])],
163 }
164 )
165
166 combo_product_9 = self.env["product.product"].create(
167 {
168 "name": "Combo Product 9",
169 "is_storable": True,
170 "available_in_pos": True,
171 "list_price": 50,
172 "taxes_id": [(6, 0, [tax20in.id])],
173 "pos_categ_ids": [(6, 0, [pos_category_3.id])],
174 }
175 )
176
177 chair_color_attribute = self.env['product.attribute'].create({
178 'name': 'Color',
179 'display_type': 'color',
180 'create_variant': 'no_variant',
181 })
182 chair_color_red = self.env['product.attribute.value'].create({
183 'name': 'Red',
184 'attribute_id': chair_color_attribute.id,
185 'html_color': '#ff0000',
186 })
187 chair_color_blue = self.env['product.attribute.value'].create({
188 'name': 'Blue',
189 'attribute_id': chair_color_attribute.id,
190 'html_color': '#0000ff',
191 })
192 self.env['product.template.attribute.line'].create({
193 'product_tmpl_id': combo_product_9.product_tmpl_id.id,
194 'attribute_id': chair_color_attribute.id,
195 'value_ids': [(6, 0, [chair_color_red.id, chair_color_blue.id])]
196 })
197
198 self.chairs_combo = self.env["product.combo"].create(
199 {
200 "name": "Chairs Combo",
201 "combo_item_ids": [
202 Command.create({
203 "product_id": combo_product_6.id,
204 "extra_price": 0,
205 }),
206 Command.create({
207 "product_id": combo_product_7.id,
208 "extra_price": 0,
209 }),
210 Command.create({
211 "product_id": combo_product_8.id,
212 "extra_price": 5,
213 }),
214 Command.create({
215 "product_id": combo_product_9.id,
216 "extra_price": 0,
217 }),
218 ],
219 }
220 )
221
222 # Create Office Combo
223 self.office_combo = self.env["product.product"].create(
224 {
225 "available_in_pos": True,
226 "list_price": 40,
227 "name": "Office Combo",
228 "type": "combo",
229 "uom_id": self.env.ref("uom.product_uom_unit").id,
230 "combo_ids": [
231 (6, 0, [self.desks_combo.id, self.chairs_combo.id, self.desk_accessories_combo.id])
232 ],
233 "pos_categ_ids": [(6, 0, [pos_category_2.id])],
234 }
235 )