This question has been flagged
1 Reply
2828 Views

Hello, evrybody!

I changed class product_template to show available products quantity to costumers.
Changes:
new function
    def _product_template_quant(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for product in self.browse(cr, uid, ids):
            if product.qty_available == 0.0:
                res[product.id] = str('Not available')
            else:
                res[product.id] = 'Available: ' + str(int(product.qty_available))
        return res
Add this function to model:
_columns={
.....
'quant': fields.function(_product_template_quant, type='char', string='Available products'),
.....}

After that i changed template
to show t-field="product.quant"

When I logged in odoo like administrator evrything go fine: i can see product quantity.
But when i`m public user (not logged on at all) i  can`t see anything.

If i change function _product_template_quant to it return constant:
    def _product_template_quant(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for product in self.browse(cr, uid, ids):
            res[product.id] = 'My test const '
        return res
evrything go fine and i see 'My test const' as public user.

So, i think the problem is acess rights for field product.qty_available for public user.
I find table ir_model_access, but i can`t understand  how to give acess to product.qty_available to public user.

Can somebody give me an example how to do that?

UPDATE: here is the warning from log.
WARNING mechanic openerp.addons.base.ir.ir_model: Access Denied by ACLs for operation: read, uid: 3, model: stock.warehouse

uid:3 it is public user.
 

Avatar
Discard
Best Answer

Denys, you can add field access control, by including a "groups" attribute in the field definition.

For eg: in the field definition of 'quant', after string='Available products', add groups="base.group_user"

Avatar
Discard