| models | ||
| static/src | ||
| __init__.py | ||
| __manifest__.py | ||
| .gitignore | ||
| README.md | ||
Web Decimal Style
This module enhances the display of decimal numbers in Odoo by styling the decimal part differently from the integer part.
Features
- Visual Enhancement: Decimal parts are styled to be smaller (80% font size) and slightly transparent (0.7 opacity), making large numbers easier to read.
- Universal Application: Works across all views (List, Form, Kanban, Pivot, etc.) and all fields (Float, Monetary, Quantity).
- Non-Invasive Architecture: Uses a safe DOM Observer approach instead of patching Odoo's internal JS formatters. This ensures maximum compatibility with other modules and Odoo updates.
- Localization Aware: Correctly handles decimal separators (dot or comma) based on the user's language settings.
Technical Details
Architecture
The module has been refactored to use a MutationObserver approach:
- Global Observer: A
MutationObserverwatches the document body for changes. - Safe Text Scanning: It scans text nodes using a
TreeWalkerto find numbers. - Regex Matching: It uses a strict Regular Expression to identify decimal parts.
- It dynamically builds the regex using Odoo's
localization.decimalPointsetting. - Example (English): Matches
123.45(.45 is styled). - Example (Indonesian): Matches
123,45(,45 is styled). - Smart Exclusion: It intelligently ignores thousands separators (e.g.,
1,200is not matched in English/US locale).
- It dynamically builds the regex using Odoo's
- DOM Wrapping: Matches are wrapped in a
<span class="o_decimal">element for styling.
Advantages
- No Conflicts: Does not override
formatFloatorformatMonetaryfunctions, avoiding conflicts with other modules that modify formatting. - Robust: Works even on custom widgets or non-standard views, as long as the number is rendered as text.
Usage
The module automatically applies decimal styling to all numeric fields. No configuration is required.
Debugging
Console
You can verify the module is running by checking the browser console:
- Look for:
"Web Decimal Style: Loading DOM Decorator observer..."
Troubleshooting
If styling is not applied:
- Check Localization: Ensure your user's language setting has the correct "Decimal Separator" configured.
- Browser Cache: Clear your browser cache or force refresh (Ctrl+Shift+R) to ensure the new JS is loaded.
- Inspect Element: Right-click a number. You should see the decimal part wrapped in:
<span class="o_decimal">.00</span>
Installation
- Install the module.
- Restart Odoo.
- Upgrade the module
web_decimal_style. - Refresh your browser.