refactor: remove decimal styling patch from inventory views

This commit is contained in:
Suherdy Yacob 2026-01-29 16:04:02 +07:00
parent 80930a9535
commit 61c3f010a9

View File

@ -6,73 +6,76 @@ import { ListRenderer } from "@web/views/list/list_renderer";
console.log('Loading inventory decimal patch...');
// Safe DOM manipulation approach to avoid Owl lifecycle conflicts
patch(ListRenderer.prototype, {
async render() {
const result = await super.render();
// Schedule decimal styling after Owl completes its rendering cycle
this.scheduleDecimalStyling();
return result;
},
// Safe DOM manipulation approach to avoid Owl lifecycle conflicts
// patch(ListRenderer.prototype, {
// async render() {
// const result = await super.render();
scheduleDecimalStyling() {
// Use requestAnimationFrame to ensure we run after Owl's DOM updates
requestAnimationFrame(() => {
try {
this.applyDecimalStyling();
} catch (error) {
console.warn('Decimal styling error (non-critical):', error);
}
});
},
// // Schedule decimal styling after Owl completes its rendering cycle
// this.scheduleDecimalStyling();
applyDecimalStyling() {
if (!this.el || !document.contains(this.el)) return;
// Find all cells in the list table, but be more careful about DOM manipulation
const cells = this.el.querySelectorAll('td:not([data-decimal-processed]), .o_data_cell:not([data-decimal-processed])');
cells.forEach(cell => {
try {
// Skip if cell is being updated by Owl
if (cell.hasAttribute('data-owl-updating')) return;
// Mark as processed to avoid double processing
cell.setAttribute('data-decimal-processed', 'true');
const text = cell.textContent?.trim();
if (!text) return;
// Check for decimal numbers (including currency)
const decimalMatch = text.match(/^(.*)(\d+)([.,])(\d+)(.*)$/);
if (decimalMatch) {
const [, prefix, integerPart, decimalPoint, decimalPart, suffix] = decimalMatch;
console.log('Applying safe DOM decimal styling to:', text);
// Create new HTML structure safely
const newHTML = `${prefix}${integerPart}<span class="o_decimal">${decimalPoint}${decimalPart}</span>${suffix}`;
// Only update if the content hasn't changed
if (cell.textContent.trim() === text) {
cell.innerHTML = newHTML;
}
}
// Handle whole numbers by adding .000
else if (text.match(/^\d+$/) && text.length > 0) {
console.log('Adding decimals to whole number safely:', text);
// Only update if the content hasn't changed
if (cell.textContent.trim() === text) {
cell.innerHTML = `${text}<span class="o_decimal">.000</span>`;
}
}
} catch (error) {
console.warn('Error processing cell (non-critical):', error);
}
});
}
});
// return result;
// },
// scheduleDecimalStyling() {
// // Use requestAnimationFrame to ensure we run after Owl's DOM updates
// requestAnimationFrame(() => {
// try {
// this.applyDecimalStyling();
// } catch (error) {
// console.warn('Decimal styling error (non-critical):', error);
// }
// });
// },
// applyDecimalStyling() {
// if (!this.el || !document.contains(this.el)) return;
// // Find all cells in the list table, but be more careful about DOM manipulation
// const cells = this.el.querySelectorAll('td:not([data-decimal-processed]), .o_data_cell:not([data-decimal-processed])');
// cells.forEach(cell => {
// try {
// // Skip if cell is being updated by Owl
// if (cell.hasAttribute('data-owl-updating')) return;
// // Mark as processed to avoid double processing
// cell.setAttribute('data-decimal-processed', 'true');
// const text = cell.textContent?.trim();
// if (!text) return;
// // Check for decimal numbers (including currency)
// const decimalMatch = text.match(/^(.*)(\d+)([.,])(\d+)(.*)$/);
// if (decimalMatch) {
// const [, prefix, integerPart, decimalPoint, decimalPart, suffix] = decimalMatch;
// console.log('Applying safe DOM decimal styling to:', text);
// // Create new HTML structure safely
// const newHTML = `${prefix}${integerPart}<span class="o_decimal">${decimalPoint}${decimalPart}</span>${suffix}`;
// // Only update if the content hasn't changed
// if (cell.textContent.trim() === text) {
// // cell.innerHTML = newHTML;
// }
// }
// // Handle whole numbers by adding .000
// else if (text.match(/^\d+$/) && text.length > 0) {
// console.log('Adding decimals to whole number safely:', text);
// // Only update if the content hasn't changed
// if (cell.textContent.trim() === text) {
// // cell.innerHTML = `${text}<span class="o_decimal">.000</span>`;
// }
// }
// } catch (error) {
// console.warn('Error processing cell (non-critical):', error);
// }
// });
// }
// });
console.log('Inventory decimal patch loaded');