Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
5 Vastaukset
4538 Näkymät

I'm tying to get the product available quantity displayed on the on the ecommerce product page.

Adding  <p t-field="product.qty_available"></p> in the the website_sale.product template does the job but information appears just when logged as a company user. Public visitors don't see it.

Is it possible to get this field visible to public visitors?

Avatar
Hylkää

product.qty_available is a calculated field and the public user don't have access to stock_workshop and stock_location. Create other field qty_pubic_available and read qty_available using SUPERUSER_ID. Example for test if product is or not in stock. class product_template(orm.Model): _inherit = 'product.template' def _is_qty_available(self, cr, uid, ids, name, args, context=None): res = {} for product in self.browse(cr, SUPERUSER_ID, ids, context=context): if product.qty_available > 0: res[product.id] = True else: res[product.id] = False return res _columns = { 'is_qty_available': fields.function(_is_qty_available, type='boolean'), 'product_brand_id': fields.many2one('product.brand', 'Brand', help='Select a brand for this product.', ondelete='restrict'), }

Tekijä

Thanks for you response. Nice to hear there is a solution. In which model do I have to create the new field? Could you give some advise on where to put the code you suggested and also why you are refering to product brand?

Paras vastaus

Try this field: product.sudo().virtual_available 

Avatar
Hylkää
Paras vastaus

Did you publish the product on website, in product form-> edit tab there is a button publish to publish the product on website. Hope it will help you

Avatar
Hylkää
Tekijä

Yes for sure, products are published on the website but stock info (using

) is not visible from public users.