Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
8569 Vistas

I am using v12 Odoo Online and I am trying to show my on hand quantity to the product pages online.

The first line of code I added to the product page was:

<h4 class="text-success">Quantity Available: <span t-field="product.qty_available"/>.</h4>

After adding this code, when I refreshed the Product page on the front end of the website, I got the error page "403: Forbidden  The page you were looking for could not be authorized." 

Is there something that prevents the "product.qty_available" field from being displayed on the product page? I have added other field to the page such as "product.uom_id" and some studio fields, without issue.

Avatar
Descartar
Mejor respuesta

'qty_available' is a computed field (in real time). Its calculations requires a user to be at least an employee. This is why public / portal users can't observe such a page.

You may show quantity under sudo():

<span t-field="product.sudo().qty_available"/>

In such a way the figure would be calculated as you are under Odoo SuperUser. Take into account that this approach might have drawbacks:

  1. It is not totally safe, altough there is no much space to retrieve extra information here

  2. In case you have some restrictions by locations, they would not be applied: a user would see ALL stocks.

As alternative you can develop an own method to calculate available quantities. In that method you can also apply sudo(), but it is possible to do that more carefully in the method.



Avatar
Descartar

Nice!! I had to do the same with:
`<t t-foreach="product.sudo().product_variant_ids" t-as="variant_id">`

Publicaciones relacionadas Respuestas Vistas Actividad
1
feb 25
1084
1
ene 24
2051
1
jun 23
2992
2
feb 21
10289
0
dic 16
5827