24 lines
1 KiB
Markdown
24 lines
1 KiB
Markdown
---
|
|
name: odoo-javascript
|
|
description: JavaScript/Odoo frontend conventions for this repo (modules, tours, events, lazy loading). Use when editing JS in static/src/js/ of Odoo addons.
|
|
metadata:
|
|
type: reference
|
|
---
|
|
|
|
# JavaScript (Odoo Web/Frontend)
|
|
|
|
## Style and conventions
|
|
- ES6+ (`let`/`const`, arrow functions). Linting with ESLint (`.eslintrc.js` at root).
|
|
- Odoo pattern: AMD modules (`odoo.define`).
|
|
- **No business logic in JS (pricing rules, stock/availability decisions, permission checks)** — these belong in Python. JS handles only rendering, DOM events, and calling Python endpoints via `ajax.jsonRpc`.
|
|
- Comments to explain hacks or workarounds.
|
|
|
|
## Key patterns
|
|
- Scripts in `static/src/js/`.
|
|
- UI tours registered with `web_tour.tour` (test: true, url, steps).
|
|
- **Delegated** events for dynamic elements (lazy loading, infinite scroll in `website_sale_aplicoop`).
|
|
- AJAX via Odoo helpers (`ajax.jsonRpc`).
|
|
|
|
## Common mistakes
|
|
- Business logic in JS → move it to Python.
|
|
- Listeners lost after DOM manipulation → reattach via event delegation.
|