diff --git a/__manifest__.py b/__manifest__.py index a6c420f..1e5c86c 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -15,10 +15,10 @@ 'web_decimal_style/static/src/css/decimal_style.css', 'web_decimal_style/static/src/core/utils/numbers_patch.js', 'web_decimal_style/static/src/views/fields/formatters_patch.js', - 'web_decimal_style/static/src/views/inventory_decimal_patch.js', - 'web_decimal_style/static/src/views/decimal_observer.js', + 'web_decimal_style/static/src/views/tax_totals_patch.js', 'web_decimal_style/static/src/views/fields/float_field.xml', 'web_decimal_style/static/src/views/fields/monetary_field.xml', + 'web_decimal_style/static/src/views/list_view_patch.xml', ], 'web.assets_backend_lazy': [ 'web_decimal_style/static/src/views/pivot_view_patch.xml', diff --git a/static/src/core/utils/numbers_patch.js b/static/src/core/utils/numbers_patch.js index 0f933d8..ba9b76a 100644 --- a/static/src/core/utils/numbers_patch.js +++ b/static/src/core/utils/numbers_patch.js @@ -1,7 +1,7 @@ import { localization } from "@web/core/l10n/localization"; import { markup } from "@odoo/owl"; -console.log('Web Decimal Style: numbers_patch.js loaded'); + /** * Wraps the decimal part of a formatted number string in a span for styling. @@ -14,15 +14,15 @@ export function wrapDecimal(formattedValue) { if (!formattedValue || typeof formattedValue !== "string") { return formattedValue; } - + // If it's already wrapped, don't double wrap if (formattedValue.includes('class="o_decimal"')) { return formattedValue; } const decimalPoint = localization.decimalPoint || '.'; - - console.log('wrapDecimal: Processing', formattedValue); + + // Handle numbers with decimal points if (formattedValue.includes(decimalPoint)) { @@ -30,7 +30,7 @@ export function wrapDecimal(formattedValue) { if (parts.length === 2) { const integerPart = parts[0]; const decimalPart = parts[1]; - + // Simple regex to separate digits from symbols const match = decimalPart.match(/^(\d+)(.*)$/); if (match) { @@ -38,19 +38,19 @@ export function wrapDecimal(formattedValue) { const symbols = match[2]; // Use simple class without inline styles const result = markup(`${integerPart}${decimalPoint}${digits}${symbols}`); - console.log('wrapDecimal: Wrapped', formattedValue); + return result; } } } - + // Handle whole numbers - force decimal formatting for inventory if (formattedValue.match(/^\d+$/)) { const result = markup(`${formattedValue}.000`); - console.log('wrapDecimal: Added decimals to whole number', formattedValue); + return result; } - - console.log('wrapDecimal: No formatting applied to', formattedValue); + + return formattedValue; } diff --git a/static/src/views/fields/formatters_patch.js b/static/src/views/fields/formatters_patch.js index cd20963..6423f4b 100644 --- a/static/src/views/fields/formatters_patch.js +++ b/static/src/views/fields/formatters_patch.js @@ -5,7 +5,7 @@ import { MonetaryField } from "@web/views/fields/monetary/monetary_field"; import { FloatField } from "@web/views/fields/float/float_field"; import { formatMonetary, formatFloat } from "@web/views/fields/formatters"; -console.log('Loading Web Decimal Style formatters patch...'); + // Safe field patching with error handling try { @@ -92,7 +92,7 @@ try { } }, { force: true }); - console.log('Web Decimal Style: Safely patched formatter', name); + } catch (error) { console.warn(`Error patching formatter ${name} (non-critical):`, error); } @@ -105,4 +105,4 @@ try { console.warn('Registry patching error (non-critical):', error); } -console.log('Web Decimal Style formatters patch loaded successfully'); + diff --git a/static/src/views/list_view_patch.xml b/static/src/views/list_view_patch.xml index 61f0c53..a007bd9 100644 --- a/static/src/views/list_view_patch.xml +++ b/static/src/views/list_view_patch.xml @@ -2,15 +2,15 @@ - - + + - - + + diff --git a/static/src/views/tax_totals_patch.js b/static/src/views/tax_totals_patch.js new file mode 100644 index 0000000..2df436a --- /dev/null +++ b/static/src/views/tax_totals_patch.js @@ -0,0 +1,32 @@ +/** @odoo-module **/ + +import { patch } from "@web/core/utils/patch"; +import { wrapDecimal } from "@web_decimal_style/core/utils/numbers_patch"; +import { TaxTotalsComponent } from "@account/components/tax_totals/tax_totals"; + + + +// Patch TaxTotalsComponent (the main widget) +patch(TaxTotalsComponent.prototype, { + formatMonetary(value) { + const result = super.formatMonetary(value); + return wrapDecimal(result); + } +}); + +// We also need to patch TaxGroupComponent which is a sub-component defined in the same file +// However, it's not exported directly in Odoo 16/17/18/19 usually, but accessible via TaxTotalsComponent.components +if (TaxTotalsComponent.components && TaxTotalsComponent.components.TaxGroupComponent) { + const TaxGroupComponent = TaxTotalsComponent.components.TaxGroupComponent; + + patch(TaxGroupComponent.prototype, { + formatMonetary(value) { + const result = super.formatMonetary(value); + return wrapDecimal(result); + } + }); +} else { + console.warn('Web Decimal Style: Could not find TaxGroupComponent to patch'); +} + +