fix for odoo 19
This commit is contained in:
parent
6d0c445279
commit
80930a9535
@ -35,11 +35,11 @@ function safelyApplyDecimalStyling(element) {
|
|||||||
// Improved patterns that properly distinguish thousands separators from decimal separators
|
// Improved patterns that properly distinguish thousands separators from decimal separators
|
||||||
const patterns = [
|
const patterns = [
|
||||||
// Currency with decimal: Rp 6,210,000.00 (comma for thousands, dot for decimal)
|
// Currency with decimal: Rp 6,210,000.00 (comma for thousands, dot for decimal)
|
||||||
/^(.*Rp\s*)(\d{1,3}(?:,\d{3})*)\.(\d{2})(.*)$/,
|
/^(.*Rp[\s\u00A0]*)(\d[\d,\s\u00A0]*)\.(\d{2})(.*)$/,
|
||||||
// Standard decimal with thousands: 1,234.56 (comma for thousands, dot for decimal)
|
// Generic decimal with thousand separators (dot as decimal)
|
||||||
/^(.*)(\d{1,3}(?:,\d{3})*)\.(\d+)(.*)$/,
|
/^(.*?)([\d,\s\u00A0]*\d)\.(\d+)(.*)$/,
|
||||||
// Simple decimal without thousands: 240.000, 123.45
|
// Simple decimal
|
||||||
/^(.*)(\d+)\.(\d+)(.*)$/
|
/^(.*?)(\d+)\.(\d+)(.*)$/
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pattern of patterns) {
|
for (const pattern of patterns) {
|
||||||
@ -47,12 +47,15 @@ function safelyApplyDecimalStyling(element) {
|
|||||||
if (match) {
|
if (match) {
|
||||||
const [, prefix, integerPart, decimalPart, suffix] = match;
|
const [, prefix, integerPart, decimalPart, suffix] = match;
|
||||||
|
|
||||||
console.log('Ultra-Safe Decimal Observer: Styling decimal number', text);
|
// console.log('Ultra-Safe Decimal Observer: MATCH FOUND', {text, prefix, integerPart, decimalPart, suffix});
|
||||||
|
|
||||||
// Triple-check the element is safe to modify
|
// Triple-check the element is safe to modify
|
||||||
|
// For tfoot, we are more permissive because they are always readonly
|
||||||
if (element.textContent.trim() === text &&
|
if (element.textContent.trim() === text &&
|
||||||
document.contains(element) &&
|
document.contains(element) &&
|
||||||
!element.closest('.o_field_widget:not(.o_readonly_modifier)')) {
|
(!element.closest('.o_field_widget:not(.o_readonly_modifier)') || element.closest('tfoot'))) {
|
||||||
|
|
||||||
|
console.log('Ultra-Safe Decimal Observer: STYLING', text, element.tagName, element.className);
|
||||||
const newHTML = `${prefix || ''}${integerPart}<span class="o_decimal">.${decimalPart}</span>${suffix || ''}`;
|
const newHTML = `${prefix || ''}${integerPart}<span class="o_decimal">.${decimalPart}</span>${suffix || ''}`;
|
||||||
element.innerHTML = newHTML;
|
element.innerHTML = newHTML;
|
||||||
return true;
|
return true;
|
||||||
@ -64,10 +67,10 @@ function safelyApplyDecimalStyling(element) {
|
|||||||
// Only add decimals to numbers that are clearly quantities in readonly contexts
|
// Only add decimals to numbers that are clearly quantities in readonly contexts
|
||||||
if (text.match(/^\d+$/) && text.length > 0 && text.length <= 4 &&
|
if (text.match(/^\d+$/) && text.length > 0 && text.length <= 4 &&
|
||||||
element.closest('.o_readonly_modifier') && (
|
element.closest('.o_readonly_modifier') && (
|
||||||
element.closest('[name="quantity"]') ||
|
element.closest('[name="quantity"]') ||
|
||||||
element.closest('[name="quantity_done"]') ||
|
element.closest('[name="quantity_done"]') ||
|
||||||
element.closest('[name="reserved_availability"]')
|
element.closest('[name="reserved_availability"]')
|
||||||
)) {
|
)) {
|
||||||
console.log('Ultra-Safe Decimal Observer: Adding decimals to readonly quantity', text);
|
console.log('Ultra-Safe Decimal Observer: Adding decimals to readonly quantity', text);
|
||||||
|
|
||||||
// Triple-check before updating
|
// Triple-check before updating
|
||||||
@ -100,11 +103,16 @@ function ultraSafelyProcessContainer(container) {
|
|||||||
if (!container || !document.contains(container)) return;
|
if (!container || !document.contains(container)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Only process elements in readonly contexts to avoid editable field conflicts
|
// Select elements likely to contain formatted decimals in readonly contexts or footers
|
||||||
const elements = container.querySelectorAll('.o_readonly_modifier td:not([data-decimal-processed]), .o_readonly_modifier span:not([data-decimal-processed]), .o_field_monetary.o_readonly_modifier:not([data-decimal-processed]), .o_field_float.o_readonly_modifier:not([data-decimal-processed])');
|
const elements = container.querySelectorAll('.o_readonly_modifier td:not([data-decimal-processed]), .o_readonly_modifier span:not([data-decimal-processed]), tfoot td:not([data-decimal-processed]), tfoot span:not([data-decimal-processed]), .o_list_number:not([data-decimal-processed])');
|
||||||
|
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
// Only process leaf elements in readonly contexts
|
// Optimization: If a TD has a SPAN, we prefer to style the SPAN to preserve tooltips
|
||||||
|
if (element.tagName === 'TD' && element.querySelector('span')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only process leaf elements or elements with very simple structures
|
||||||
if ((element.children.length === 0 ||
|
if ((element.children.length === 0 ||
|
||||||
(element.children.length === 1 && element.children[0].tagName === 'SPAN')) &&
|
(element.children.length === 1 && element.children[0].tagName === 'SPAN')) &&
|
||||||
!element.hasAttribute('data-owl-updating') &&
|
!element.hasAttribute('data-owl-updating') &&
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user