跳至內容
選單
此問題已被標幟
5 回覆
4555 瀏覽次數

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?

頭像
捨棄

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'), }

作者

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?

最佳答案

Try this field: product.sudo().virtual_available 

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

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

) is not visible from public users.