Quick reference index for the website_sale_aplicoop template error fix: - Links to detailed analysis (FIX_TEMPLATE_ERROR_SUMMARY.md) - Links to best practices guide (QWEB_BEST_PRACTICES.md) - One-page summary of problem, cause, and solution - Quick reference cards for safe variable patterns - Navigation structure for easy access to all fix-related docs This file serves as the entry point for understanding the template fix and accessing all related documentation in one place.
235 lines
6.2 KiB
Markdown
235 lines
6.2 KiB
Markdown
# Template Error Fix - Complete Reference Index
|
|
|
|
**Status**: ✅ RESOLVED
|
|
**Module**: website_sale_aplicoop v18.0.1.1.1
|
|
**Date**: 2026-02-16
|
|
|
|
---
|
|
|
|
## Quick Links
|
|
|
|
### 📋 Problem & Solution
|
|
- **Main Reference**: [FIX_TEMPLATE_ERROR_SUMMARY.md](FIX_TEMPLATE_ERROR_SUMMARY.md)
|
|
- Root cause analysis
|
|
- Solution explanation
|
|
- Verification results
|
|
|
|
### 📚 Development Standards
|
|
- **Best Practices Guide**: [QWEB_BEST_PRACTICES.md](QWEB_BEST_PRACTICES.md)
|
|
- QWeb patterns and examples
|
|
- Common pitfalls to avoid
|
|
- Real-world code samples
|
|
|
|
### 🔧 Implementation Details
|
|
- **Modified File**: [website_templates.xml](../website_sale_aplicoop/views/website_templates.xml)
|
|
- Lines 1217-1224: Safe variable definitions
|
|
- Template: `eskaera_shop_products`
|
|
|
|
### 📦 Git History
|
|
```
|
|
6fed863 [DOC] Add QWeb template best practices and error fix documentation
|
|
0a0cf5a [FIX] website_sale_aplicoop: Replace or operators with t-set safe variables
|
|
df57233 [FIX] website_sale_aplicoop: Fix NoneType error in eskaera_shop_products template
|
|
```
|
|
|
|
---
|
|
|
|
## The Problem (Short Version)
|
|
|
|
**Error**: `TypeError: 'NoneType' object is not callable`
|
|
|
|
**Cause**: QWeb parsing of `or` operators in `t-attf-*` attributes fails when values are None
|
|
|
|
**Example**:
|
|
```xml
|
|
<!-- ❌ BROKEN -->
|
|
<form t-attf-data-price="{{ price1 or price2 or 0 }}">
|
|
```
|
|
|
|
---
|
|
|
|
## The Solution (Short Version)
|
|
|
|
**Pattern**: Pre-compute safe values with `t-set` before using in attributes
|
|
|
|
**Example**:
|
|
```xml
|
|
<!-- ✅ FIXED -->
|
|
<t t-set="safe_price" t-value="price1 if price1 else (price2 if price2 else 0)"/>
|
|
<form t-attf-data-price="{{ safe_price }}">
|
|
```
|
|
|
|
---
|
|
|
|
## Key Changes Summary
|
|
|
|
| Aspect | Before | After |
|
|
|--------|--------|-------|
|
|
| **Pattern** | Inline `or` operators | Pre-computed `t-set` |
|
|
| **Error** | TypeError on None values | Safe handling of None |
|
|
| **Code lines** | 7 | 15 |
|
|
| **QWeb compatible** | ❌ No | ✅ Yes |
|
|
| **Testable** | ❌ Hard | ✅ Easy |
|
|
|
|
---
|
|
|
|
## Files in This Series
|
|
|
|
1. **THIS FILE** (TEMPLATE_FIX_INDEX.md)
|
|
- Quick navigation and overview
|
|
- Links to detailed documentation
|
|
- Summary reference
|
|
|
|
2. [FIX_TEMPLATE_ERROR_SUMMARY.md](FIX_TEMPLATE_ERROR_SUMMARY.md)
|
|
- Complete analysis of the error
|
|
- Step-by-step solution explanation
|
|
- Verification and testing results
|
|
- Debugging information
|
|
|
|
3. [QWEB_BEST_PRACTICES.md](QWEB_BEST_PRACTICES.md)
|
|
- QWeb template development guide
|
|
- 3 None-safety patterns with examples
|
|
- 3 Variable computation patterns
|
|
- Common pitfalls and solutions
|
|
- Real-world code examples
|
|
- Summary reference table
|
|
|
|
---
|
|
|
|
## When to Use Each Document
|
|
|
|
### 📋 Read FIX_TEMPLATE_ERROR_SUMMARY.md if:
|
|
- You want to understand what the problem was
|
|
- You need to verify the fix is applied
|
|
- You're debugging similar template errors
|
|
- You want the full error-to-solution journey
|
|
|
|
### 📚 Read QWEB_BEST_PRACTICES.md if:
|
|
- You're writing new QWeb templates
|
|
- You want to avoid similar issues in future
|
|
- You need QWeb patterns and examples
|
|
- You're doing code review of templates
|
|
- You want to improve template code quality
|
|
|
|
### 🔧 Read template file directly if:
|
|
- You need to modify the fixed code
|
|
- You want to see the exact syntax
|
|
- You're learning from working code
|
|
|
|
---
|
|
|
|
## One-Page Summary
|
|
|
|
### The Error
|
|
```
|
|
Traceback (most recent call last):
|
|
File "...", line XX, in ...
|
|
ValueError: TypeError: 'NoneType' object is not callable
|
|
eskaera_shop_products template at line ...
|
|
```
|
|
|
|
### The Root Cause
|
|
QWeb's `t-attf-*` (template attribute) directives evaluate expressions in a way that doesn't handle chained `or` operators well when values are `None`.
|
|
|
|
### The Fix
|
|
Replace inline operators with pre-computed safe variables using `t-set`:
|
|
|
|
```xml
|
|
<!-- Before (broken) -->
|
|
<form t-attf-data-price="{{ price1 or price2 or 0 }}"/>
|
|
|
|
<!-- After (fixed) -->
|
|
<t t-set="safe_price" t-value="price1 if price1 else (price2 if price2 else 0)"/>
|
|
<form t-attf-data-price="{{ safe_price }}"/>
|
|
```
|
|
|
|
### The Result
|
|
✅ Template loads without errors
|
|
✅ All tests passing
|
|
✅ Safe pattern documented
|
|
✅ Best practices established
|
|
|
|
---
|
|
|
|
## Quick Reference Cards
|
|
|
|
### Safe Variable Pattern
|
|
```xml
|
|
<t t-set="variable_name"
|
|
t-value="preferred_value if preferred_value else fallback_value"/>
|
|
```
|
|
|
|
### Safe Nested Access
|
|
```xml
|
|
<t t-set="safe_value"
|
|
t-value="obj.nested.value if (obj and obj.nested) else default"/>
|
|
```
|
|
|
|
### Safe Chained Fallback
|
|
```xml
|
|
<t t-set="safe_value"
|
|
t-value="val1 if val1 else (val2 if val2 else (val3 if val3 else default))"/>
|
|
```
|
|
|
|
---
|
|
|
|
## Testing the Fix
|
|
|
|
### Verification Steps
|
|
1. Module loads without parsing errors ✅
|
|
2. Template compiles in ir.ui.view ✅
|
|
3. Safe variables are present ✅
|
|
4. All 85 unit tests pass ✅
|
|
5. Docker services stable ✅
|
|
|
|
### How to Re-verify
|
|
```bash
|
|
# Check template in database
|
|
docker-compose exec -T odoo odoo shell -d odoo -c /etc/odoo/odoo.conf << 'SHELL'
|
|
template = env['ir.ui.view'].search([('name', '=', 'Eskaera Shop Products')])
|
|
print('safe_display_price' in template.arch) # Should print True
|
|
SHELL
|
|
```
|
|
|
|
---
|
|
|
|
## Common Questions
|
|
|
|
**Q: Why not just fix the template in code?**
|
|
A: We did - that's the fix! But the pattern is important for preventing future issues.
|
|
|
|
**Q: Can I use this pattern in other templates?**
|
|
A: Yes! This is now the standard pattern for all Odoo templates in this project.
|
|
|
|
**Q: What if I need more complex logic?**
|
|
A: You can chain multiple `t-set` statements, each computing one safe variable.
|
|
|
|
**Q: Does this impact performance?**
|
|
A: No - `t-set` is evaluated once during template compilation, not on each render.
|
|
|
|
---
|
|
|
|
## Related Resources
|
|
|
|
- [Odoo QWeb Documentation](https://www.odoo.com/documentation/18.0/developer/reference/frontend/qweb.html)
|
|
- [Odoo Template Reference](https://www.odoo.com/documentation/18.0/developer/reference/backend/orm.html#templates)
|
|
- [Python Ternary Expressions](https://docs.python.org/3/tutorial/controlflow.html#more-on-conditions)
|
|
|
|
---
|
|
|
|
## Navigation
|
|
|
|
```
|
|
docs/
|
|
├── TEMPLATE_FIX_INDEX.md (YOU ARE HERE)
|
|
├── FIX_TEMPLATE_ERROR_SUMMARY.md (Complete analysis)
|
|
├── QWEB_BEST_PRACTICES.md (Development guide)
|
|
├── README.md (Project documentation index)
|
|
└── ... (other documentation)
|
|
```
|
|
|
|
---
|
|
|
|
**Last Updated**: 2026-02-16
|
|
**Status**: ✅ Production Ready
|
|
**Version**: Odoo 18.0.20251208
|