[SOLVED] remove duplicate on rendering

This commit is contained in:
ahiexp 2025-05-29 10:55:53 +04:00
parent a5d618cc93
commit 8645f85905
1 changed files with 34 additions and 16 deletions

View File

@ -10,31 +10,49 @@ odoo.define('simplify_access_management.hide_export', function (require) {
_render: function () {
const res = this._super.apply(this, arguments);
const self = this;
this._super.apply(this, arguments);
// this._super.apply(this, arguments);
var hash = window.location.hash.replace("#", '').split("&");
let cids;
if(hash.findIndex(ele => ele.includes("cid")) == -1)
if (hash.findIndex(ele => ele.includes("cid")) == -1)
cids = session.company_id;
else {
cids = hash.filter(ele => ele.includes("cid"))[0].split("=")[1].split(",");
cids = cids.length > 0? parseInt(cids[0]): session.company_id;
cids = cids.length > 0 ? parseInt(cids[0]) : session.company_id;
}
let model = hash.filter(ele=>ele.includes("model"))?.[0];
model = model? model.split("=")?.[1].split(",")?.[0]: model;
if(cids && model) {
let model = hash.filter(ele => ele.includes("model"))?.[0];
model = model ? model.split("=")?.[1].split(",")?.[0] : model;
if (cids && model) {
rpc.query({
model:'access.management',
model: 'access.management',
method: 'is_export_hide',
args: [cids, model]
}).then(function(result){
if(result) {
var btn1 = setInterval(function() {
if ($('.o_list_export_xlsx').length) {
$('.o_list_export_xlsx').remove();
clearInterval(btn1);
}).then(function (result) {
if (result) {
// dump code
// var btn1 = setInterval(function () {
// if ($('.o_list_export_xlsx').length) {
// $('.o_list_export_xlsx').remove();
// clearInterval(btn1);
// }
// }, 50);
// replace setInterval by MutationObserver
// It reacts only when changes actually happen in the DOM
// Cleaner logic and easier to control when disconnecting
const observer = new MutationObserver(function (mutations, obs) {
const exportBtn = document.querySelector('.o_list_export_xlsx');
if (exportBtn) {
exportBtn.remove();
obs.disconnect(); // Stop observing once the button is removed
}
}, 50);
});
// Start observing the body (or a more specific container)
observer.observe(document.body, {
childList: true,
subtree: true
});
}
});
}