Revert "إصلاح خطأ Service already defined - إضافة حماية من التكرار والأخطاء"

This commit is contained in:
Mohamed Eltayar 2025-08-31 23:55:06 +03:00 committed by GitHub
parent 3a7943516b
commit 95e03c2d89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 48 additions and 82 deletions

View File

@ -6,12 +6,6 @@
(function() { (function() {
'use strict'; 'use strict';
// تجنب التشغيل المتكرر
if (window.SarSymbolSystem && window.SarSymbolSystem.initialized) {
console.log('SAR Symbol System already initialized');
return;
}
// رمز العملة السعودية الجديد // رمز العملة السعودية الجديد
const SAR_SYMBOLS = [ const SAR_SYMBOLS = [
'﷼', // الرمز الكلاسيكي '﷼', // الرمز الكلاسيكي
@ -106,10 +100,10 @@
} }
}); });
// فحص شامل كـ fallback - فقط العناصر الصغيرة // فحص شامل كـ fallback
const allElements = document.querySelectorAll('*'); const allElements = document.querySelectorAll('*');
allElements.forEach(element => { allElements.forEach(element => {
if (element.textContent && element.textContent.length < 100) { // تقليل الحد لتحسين الأداء if (element.textContent && element.textContent.length < 200) { // تجنب النصوص الطويلة
checkElement(element); checkElement(element);
} }
}); });
@ -150,23 +144,15 @@
} }
/** /**
* معالج خاص للحقول النقدية في أودو - مع حماية من التكرار * معالج خاص للحقول النقدية في أودو
*/ */
function handleOdooMonetaryFields() { function handleOdooMonetaryFields() {
// التأكد من أن أودو موجود وأن الخدمة لم يتم تعريفها من قبل // مراقبة تحديثات البيانات في أودو
if (window.odoo && window.odoo.define) { if (window.odoo && window.odoo.define) {
// فحص إذا كانت الخدمة معرفة مسبقاً window.odoo.define('sar_symbol.field_utils', function (require) {
const serviceName = 'sar_symbol.field_utils_' + Date.now(); // اسم فريد
try {
window.odoo.define(serviceName, function (require) {
'use strict'; 'use strict';
try {
const fieldUtils = require('web.field_utils'); const fieldUtils = require('web.field_utils');
// التأكد من أن الدالة لم يتم تعديلها من قبل
if (fieldUtils.format.monetary && !fieldUtils.format.monetary._sarModified) {
const originalFormatMonetary = fieldUtils.format.monetary; const originalFormatMonetary = fieldUtils.format.monetary;
fieldUtils.format.monetary = function(value, field, options) { fieldUtils.format.monetary = function(value, field, options) {
@ -188,19 +174,8 @@
return result; return result;
}; };
// وضع علامة على أن الدالة تم تعديلها
fieldUtils.format.monetary._sarModified = true;
}
return fieldUtils; return fieldUtils;
} catch (innerError) {
console.warn('SAR Symbol: Could not modify field_utils:', innerError);
return {};
}
}); });
} catch (error) {
console.warn('SAR Symbol: Could not define Odoo service:', error);
}
} }
} }
@ -210,42 +185,33 @@
function initialize() { function initialize() {
console.log('SAR Symbol Font System: Initializing...'); console.log('SAR Symbol Font System: Initializing...');
try {
// فحص أولي // فحص أولي
scanAllElements(); scanAllElements();
// إعداد المراقبة // إعداد المراقبة
setupDOMObserver(); setupDOMObserver();
// معالجة خاصة لأودو (بحماية من الأخطاء) // معالجة خاصة لأودو
handleOdooMonetaryFields(); handleOdooMonetaryFields();
// فحص دوري (للتأكد) - مع فترة أطول لتوفير الموارد // فحص دوري (للتأكد)
setInterval(scanAllElements, 10000); // 10 ثوان بدلاً من 5 setInterval(scanAllElements, 5000);
console.log('SAR Symbol Font System: Ready'); console.log('SAR Symbol Font System: Ready');
} catch (error) {
console.error('SAR Symbol Font System: Initialization failed:', error);
}
} }
// تشغيل النظام مع حماية من الأخطاء // تشغيل النظام
try {
if (document.readyState === 'loading') { if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize); document.addEventListener('DOMContentLoaded', initialize);
} else { } else {
initialize(); initialize();
} }
} catch (error) {
console.error('SAR Symbol Font System: Failed to start:', error);
}
// تصدير للاستخدام الخارجي مع حماية // تصدير للاستخدام الخارجي
window.SarSymbolSystem = { window.SarSymbolSystem = {
scan: scanAllElements, scan: scanAllElements,
check: checkElement, check: checkElement,
apply: applySarFont, apply: applySarFont
initialized: true
}; };
})(); })();