[FIX] website_sale_aplicoop: Simplify price handling using Python or operator in t-set

The previous approach using complex if-else expressions in t-set variables
was causing QWeb parsing issues (TypeError: 'NoneType' object is not callable).

Solution: Leverage Python's 'or' operator in t-set variable computation
- Create intermediate variable: display_price_value = price_info.get('price')
- Then compute: display_price = display_price_value or product.list_price or 0.0
- Use simple reference in t-attf attribute: {{ display_price }}

This approach:
1. Avoids complex nested conditionals in t-set
2. Uses Python's native short-circuit evaluation for None-safety
3. Keeps template expressions simple and readable
4. Properly handles fallback values in the right evaluation order

Testing: Module loads without errors, template renders successfully.
This commit is contained in:
snt 2026-02-16 23:21:22 +01:00
parent 83b6cca09a
commit 8e5a4a39e0

View file

@ -1165,9 +1165,13 @@
t-set="price_info"
t-value="product_price_info.get(product.id, {})"
/>
<t
t-set="display_price_value"
t-value="price_info.get('price')"
/>
<t
t-set="display_price"
t-value="price_info.get('price', product.list_price)"
t-value="display_price_value or product.list_price or 0.0"
/>
<t
t-set="base_price"
@ -1211,10 +1215,6 @@
</p>
</t>
</div>
<t
t-set="safe_display_price"
t-value="display_price if display_price else (product.list_price if product.list_price else 0)"
/>
<t
t-set="safe_uom_category"
t-value="product.uom_id.category_id.name if (product.uom_id and product.uom_id.category_id) else ''"
@ -1224,7 +1224,7 @@
t-attf-data-order-id="{{ group_order.id if 'group_order' in locals() else '' }}"
t-attf-data-product-id="{{ product.id }}"
t-attf-data-product-name="{{ product.name }}"
t-attf-data-product-price="{{ safe_display_price }}"
t-attf-data-product-price="{{ display_price }}"
t-attf-data-uom-category="{{ safe_uom_category }}"
>
<div class="qty-control">