How can I display "Out of Stock" on Products on Website automatically when Quantity on Hand is less than Zero?

572 Views Asked by At

Hi, I am trying (in Odoo 10), if product quantity on hand is zero than show "Out of Stock" on Website. Following code is working fine when I am logged in as Admin, but in case of normal website visitor it gives, "500: Internal Server Error" Any solution Please? Screenshot

1

There are 1 best solutions below

0
Tiki On BEST ANSWER

This happens because qty_available is a function field that calls the _compute_quantities method. This method accesses to different models, so when entering with no user or with one without the necessary permissions odoo raises AccessError.

To fix this problem, let's access the field through sudo()

<t t-if="product.sudo().qty_available &lt;= 0">
    <div class="ribbon-wrapper out-of-stock" style="display: inherit !important;">
        <div class="ribbon btn btn-danger">Out of Stock</div>
    </div>
</t>