Debian Codegraph @

addons/website_sale/views/variant_templates.xml

raw
1 <?xml version="1.0" encoding="utf-8"?>
2 <odoo>
3 <template id="variants">
4 <t t-set="attribute_exclusions" t-value="product._get_attribute_exclusions(parent_combination)"/>
5 <t
6 t-set="has_configurable_attribute_line"
7 t-value="any(ptal._is_configurable() for ptal in product.attribute_line_ids)"
8 />
9 <ul
10 t-attf-class="o_wsale_product_page_variants d-flex flex-column gap-4 list-unstyled js_add_cart_variants #{ul_class} #{'d-none' if not has_configurable_attribute_line else '' }"
11 t-att-data-attribute-exclusions="json.dumps(attribute_exclusions)"
12 >
13 <t t-foreach="product.valid_product_template_attribute_line_ids" t-as="ptal">
14 <t t-set="attribute" t-value="ptal.attribute_id"/>
15 <t t-set="ptavs" t-value="ptal.product_template_value_ids._only_active()"/>
16 <t t-set="single" t-value="len(ptavs) == 1"/>
17
18 <!-- Attributes selection is hidden if there is only one value available and it's not a custom value -->
19 <li name="variant_attribute"
20 t-att-data-attribute-id="attribute.id"
21 t-att-data-attribute-name="attribute.name"
22 t-att-data-attribute-display-type="attribute.display_type"
23 t-attf-class="variant_attribute #{
24 'd-none' if single
25 and not ptavs[0].is_custom
26 and not attribute.display_type == 'multi' else ''
27 }">
28
29 <!-- Used to customize layout if the only available attribute value is custom -->
30 <t t-set="single_and_custom" t-value="single and ptavs[0].is_custom"/>
31 <h6 class="attribute_name mb-2">
32 <span t-field="ptal.attribute_id.name"/>
33 <span t-if="attribute.display_type in ['color', 'image']" class="text-muted">
34 -
35 <t
36 t-set="active_ptavs"
37 t-value="[ptav for ptav in ptavs if ptav in combination]"
38 />
39 <t t-foreach="active_ptavs" t-as="ptav">
40 <span class="attribute_value" name="attribute_value" t-field="ptav.name"/>
41 </t>
42 </span>
43 </h6>
44
45 <t t-if="attribute.display_type == 'select'">
46 <select
47 t-att-data-attribute-id="attribute.id"
48 t-attf-class="form-select css_attribute_select o_wsale_product_attribute js_variant_change #{attribute.create_variant} #{'d-none' if single_and_custom else ''}"
49 t-att-name="'ptal-%s' % ptal.id">
50 <t t-foreach="ptavs" t-as="ptav">
51 <option t-att-value="ptav.id"
52 t-att-data-attribute-value-id="ptav.product_attribute_value_id.id"
53 t-att-data-value-id="ptav.id"
54 t-att-data-value-name="ptav.name"
55 t-att-data-attribute-name="attribute.name"
56 t-att-data-is-custom="ptav.is_custom"
57 t-att-selected="ptav in combination">
58 <span t-field="ptav.name"/>
59 <t t-call="website_sale.badge_extra_price"/>
60 </option>
61 </t>
62 </select>
63 </t>
64
65 <t t-elif="attribute.display_type in ('radio', 'multi')">
66 <ul
67 t-att-data-attribute-id="attribute.id"
68 t-attf-class="o_wsale_product_attribute d-flex flex-wrap gap-3 list-unstyled #{'d-none' if single_and_custom else ''}"
69 >
70 <t t-foreach="ptavs" t-as="ptav">
71 <li class="js_attribute_value">
72 <label class="col-form-label p-0">
73 <div class="form-check cursor-pointer">
74 <input t-att-type="'radio' if attribute.display_type == 'radio' else 'checkbox'"
75 t-attf-class="form-check-input js_variant_change #{attribute.create_variant}"
76 t-att-checked="ptav in combination"
77 t-att-title="ptav.name"
78 t-att-name="'ptal-%s' % ptal.id"
79 t-att-value="ptav.id"
80 t-att-data-attribute-value-id="ptav.product_attribute_value_id.id"
81 t-att-data-value-id="ptav.id"
82 t-att-data-value-name="ptav.name"
83 t-att-data-attribute-name="attribute.name"
84 t-att-data-is-custom="ptav.is_custom"/>
85 <div class="radio_input_value form-check-label">
86 <span t-field="ptav.name"/>
87 <t t-call="website_sale.badge_extra_price"/>
88 </div>
89 </div>
90 </label>
91 </li>
92 </t>
93 </ul>
94 </t>
95
96 <t t-elif="attribute.display_type == 'pills'">
97 <ul
98 t-att-data-attribute-id="attribute.id"
99 t-attf-class="o_wsale_product_attribute d-flex flex-wrap list-unstyled gap-2 #{'d-none' if single_and_custom else ''}"
100 data-bs-toggle="buttons"
101 >
102 <t t-foreach="ptavs" t-as="ptav">
103 <li t-attf-class="o_variant_pills js_attribute_value border btn m-0 cursor-pointer #{'active border-primary text-primary-emphasis bg-primary-subtle' if ptav in combination else ''}">
104 <input type="radio"
105 t-attf-class="js_variant_change position-absolute #{attribute.create_variant} opacity-0 cursor-pointer"
106 t-att-checked="ptav in combination"
107 t-att-name="'ptal-%s' % ptal.id"
108 t-att-value="ptav.id"
109 t-att-data-value-id="ptav.id"
110 t-att-id="ptav.id"
111 t-att-data-attribute-value-id="ptav.product_attribute_value_id.id"
112 t-att-data-value-name="ptav.name"
113 t-att-data-attribute-name="attribute.name"
114 t-att-data-is-custom="ptav.is_custom"
115 t-att-autocomplete="off"/>
116 <label class="radio_input_value o_variant_pills_input_value cursor-pointer"
117 t-att-for="ptav.id">
118 <span t-field="ptav.name"/>
119 <t t-call="website_sale.badge_extra_price"/>
120 </label>
121 </li>
122 </t>
123 </ul>
124 </t>
125
126 <t t-elif="attribute.display_type == 'color'">
127 <ul
128 t-att-data-attribute-id="attribute.id"
129 t-attf-class="o_wsale_product_attribute d-flex flex-wrap gap-2 list-unstyled #{'d-none' if single_and_custom else ''}"
130 >
131 <li t-foreach="ptavs" t-as="ptav">
132 <t t-set="img_style"
133 t-value="'background: url(/web/image/product.template.attribute.value/%s/image); background-size: cover; ' % ptav.id if ptav.image else ''"
134 />
135 <t t-set="color_style"
136 t-value="'background:' + str(ptav.html_color or ptav.name if not ptav.is_custom else '')"
137 />
138 <label t-attf-style="#{img_style or color_style}"
139 t-attf-class="css_attribute_color cursor-pointer #{'active' if ptav in combination else ''} #{'custom_value' if ptav.is_custom else ''} #{'transparent' if (not ptav.is_custom and not ptav.html_color) else ''}"
140 >
141 <input type="radio"
142 t-attf-class="js_variant_change cursor-pointer #{attribute.create_variant}"
143 t-att-checked="ptav in combination"
144 t-att-name="'ptal-%s' % ptal.id"
145 t-att-value="ptav.id"
146 t-att-title="ptav.name"
147 t-att-data-attribute-value-id="ptav.product_attribute_value_id.id"
148 t-att-data-value-id="ptav.id"
149 t-att-data-value-name="ptav.name"
150 t-att-data-attribute-name="attribute.name"
151 t-att-data-is-custom="ptav.is_custom"/>
152 </label>
153 </li>
154 </ul>
155 </t>
156
157 <t t-elif="attribute.display_type == 'image'">
158 <ul
159 t-att-data-attribute-id="attribute.id"
160 t-attf-class="list-inline o_wsale_product_attribute #{'d-none' if single_and_custom else ''}"
161 >
162 <li t-foreach="ptavs" t-as="ptav" class="list-inline-item me-2 mb-2">
163 <label
164 name="o_wsale_attribute_image_selector"
165 t-attf-style="#{'background-image: url(/web/image/product.template.attribute.value/%s/image); background-size:cover;' % ptav.id if ptav.image else ''}"
166 t-attf-class="css_attribute_image oe_img_bg o_bg_img_center position-relative d-inline-block rounded-3 bg-body text-center cursor-pointer #{'active' if ptav in combination else ''} #{'custom_value' if ptav.is_custom else ''} #{'transparent' if (not ptav.is_custom and not ptav.html_color) else ''}"
167 >
168 <input
169 type="radio"
170 t-attf-class="js_variant_change w-100 h-100 opacity-0 cursor-pointer #{attribute.create_variant}"
171 t-att-checked="ptav in combination"
172 t-att-name="'ptal-%s' % ptal.id"
173 t-att-value="ptav.id"
174 t-att-title="ptav.name"
175 t-att-data-attribute-value-id="ptav.product_attribute_value_id.id"
176 t-att-data-value-id="ptav.id"
177 t-att-data-value-name="ptav.name"
178 t-att-data-attribute-name="attribute.name"
179 t-att-data-is-custom="ptav.is_custom"
180 />
181 </label>
182 </li>
183 </ul>
184 </t>
185 </li>
186 </t>
187 </ul>
188 <ul
189 t-if="product._has_multiple_uoms()"
190 t-attf-class="o_wsale_product_page_variants d-flex flex-column gap-4 list-unstyled js_add_cart_variants mt-4 #{ul_class}"
191 t-att-data-attribute-exclusions="json.dumps(attribute_exclusions)"
192 >
193 <!-- NOTE: the t-att-data-attribute-exclusions is only there to match existing events selectors -->
194 <li>
195 <!-- Separate template to reduce views duplication -->
196 <t t-call="website_sale.packaging_title"/>
197 <ul class="btn-group-toggle list-inline list-unstyled" data-bs-toggle="buttons">
198 <t t-set="product_uoms" t-value="product._get_available_uoms()"/>
199 <t t-foreach="product_uoms" t-as="uom">
200 <t t-set="is_main_uom" t-value="uom.id == product.uom_id.id"/>
201 <li t-attf-class="o_variant_pills border btn m-0 cursor-pointer #{'active border-primary text-primary-emphasis bg-primary-subtle' if is_main_uom else ''}">
202 <input
203 class="position-absolute opacity-0 cursor-pointer"
204 type="radio"
205 t-att-checked="is_main_uom"
206 name="uom_id"
207 t-att-value="uom.id"
208 t-attf-id="uom-{{uom.id}}"
209 t-att-autocomplete="off"/>
210 <label class="radio_input_value cursor-pointer" t-attf-for="uom-{{uom.id}}">
211 <span t-field="uom.name"/>
212 </label>
213 </li>
214 </t>
215 </ul>
216 </li>
217 </ul>
218 </template>
219 <template id="badge_extra_price" name="Badge Extra Price">
220 <t t-set="price_extra" t-value="ptav._get_extra_price(combination_info)"/>
221 <span t-if="price_extra" t-attf-class="{{'badge text-bg-primary' if attribute.display_type != 'pills' else 'small text-muted'}}">
222 <!--
223 price_extra is displayed as catalog price instead of
224 price after pricelist because it is impossible to
225 compute. Indeed, the pricelist rule might depend on the
226 selected variant, so the price_extra will be different
227 depending on the selected combination. The price of an
228 attribute is therefore variable and it's not very
229 accurate to display it.
230 -->
231 <t t-if="attribute.display_type in ['pills', 'select']">(</t><span class="sign_badge_price_extra"><t t-out="price_extra > 0 and '+' or '-'"/></span>
232 <span
233 t-out="abs(price_extra)"
234 class="variant_price_extra"
235 style="white-space: nowrap;"
236 t-options='{
237 "widget": "monetary",
238 "display_currency": website.currency_id
239 }'/><t t-if="attribute.display_type in ['pills', 'select']">)</t>
240 </span>
241 </template>
242 <template id="website_sale.packaging_title" name="Packaging title">
243 <h6 class="attribute_name mb-2">Packaging</h6>
244 </template>
245 </odoo>