Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
910 Vizualizări

Im trying to get ir.config_parameter with the next code, but i dont receive anything as output. the code must to retrieve a url from the parameter when onclick event of the button and then open that url. but open a void url.

 

<button id="my-button" onclick="openUrl()">Haz clic aquí</button> 


<script> 

    document.addEventListener('DOMContentLoaded', function() { 

        // Llamada para obtener el valor del parámetro técnico 

        fetch('/web/dataset/call_kw/ir.config_parameter/get_param', { 

            method: 'POST', 

            headers: { 

                'Content-Type': 'application/json', 

                'X-CSRF-Token': odoo.csrf_token // Token para la seguridad 

            }, 

            body: JSON.stringify({ 

                model: 'ir.config_parameter', 

                method: 'get_param', 

                args: ['your_parameter_name'], // Cambia 'your_parameter_name' por tu parámetro real 

                kwargs: {} 

            }) 

        }) 

        .then(response => response.json()) 

        .then(data => { 

            const paramValue = data.result; // Aquí obtienes el valor del parámetro 


            // Cambiamos la URL del botón dinámicamente 

            const button = document.getElementById('my-button'); 


            // Define la función que se ejecutará al hacer clic en el botón 

            window.openUrl = function() { 

                window.open(paramValue, '_blank'); // Cambia a la URL que has traído en una nueva pestaña 

            }; 

        }) 

        .catch(err => console.error('Error al obtener el parámetro:', err)); 

    }); 

</script>

Imagine profil
Abandonează
Cel mai bun răspuns

Hi sanchez


get_param is a method from ir.config_parameter which is only accessible by the group system admin


in the backed when creating code we use sudo, example


request.env['ir.config_parameter'].sudo().get_param(..


It's not recommended for front end to use sudo as this will cause a security issue

the best approach is to create a method in the backend that return only the parameter needed

in your case 

Class SaleOrderExt(models.Model):
​def get_sales_sys_params(self, arg):
​return self.env['ir.config_parameter'].sudo().get_param(..) # from arg


in your js then 

body: JSON.stringify({ 
                model: 'sale.order',
                method: 'get_sales_sys_params',
                args: ['your_parameter_name'], // Cambia 'your_parameter_name' por tu parámetro real
                kwargs: {}
            })


you can also use an apprach with request instead of self as you are dealing with website sale, but I guess you get my point


Hope this helps

Daniel


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
aug. 24
1429
1
feb. 25
1367
0
nov. 24
872
1
iun. 24
1412
1
iun. 25
572