Skip to Content
Menú
This question has been flagged
1 Respondre
8598 Vistes

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
Best Answer

'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">`

Related Posts Respostes Vistes Activitat
1
de febr. 25
1119
1
de gen. 24
2075
1
de juny 23
3028
2
de febr. 21
10372
0
de des. 16
5863