Skip to Content
Menu
This question has been flagged
1 Reply
2382 Views

hi i use this code to load js file but when user not login not work


<template id="assets_hide_price" inherit_id="website.assets_frontend">
    <xpath expr="." position="inside">
        <t t-if="request and request.env['res.config.settings'].search([('website_id','=', request.website.id)], order='id desc', limit=1).website_hide_price">
            <script type="text/javascript" src="/website_sale_customize/static/src/js/website_hide_price.js"/>
        </t>
    </xpath>
</template>
Avatar
Discard
Best Answer

Hi,

The issue might be that the public user does not have the permission to read the value from the corresponding model, that might be the case why it is not working for the non logged peoples. Either you can give read access for the public user to corresponding model or use sudo in code to bypass access rights. 

Giving read access for the public user should be done carefully.


<t t-if="request and request.env['res.config.settings'].sudo().search([('website_id','=', request.website.id)], order='id desc', limit=1).website_hide_price">
<script type="text/javascript" src="/website_sale_customize/static/src/js/website_hide_price.js"/>
</t>


Thanks

Avatar
Discard

I wouldn't ever recommend to giving read rights on such an important table as the configuration settings honestly. Your sudo() should work though ;-)