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