Search code examples
odooopenerp-7openerp-8odoo-8

dictionary update sequence element #0 has length 1; 2 is required


i look this error i all internet but i really dont understand the answers, i hard to understand what is the function given to you or what it has to give to you, i let you my code i hope any one help

What im looking for? i need to put into act_user_suc the users sucursal_u fro res_users thats all and i relly apreciated the help

class bodega(osv.Model):
    _name = 'bodega'
    _description = 'datos generales'

    def dame_usuario(self, cr, uid, ids, fieldname, arg, context=None):
        digits = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id
        return digits

    _columns = {            
                'name': fields.char("Name", required=True),
                'act_user_suc': fields.function(dame_usuario, type='many2one', readonly = True),
                }
    _defaults = {
                }
bodega()

Solution

  • You need to update few things in code.

    Specify relation attribute in fields.function, you have defined that many2one as field type but it's related to which model ?.

    And other things is that company_id.currency_id it gives you an browsable object not an id.

    So try following,

    def dame_usuario(self, cr, uid, ids, fieldname, arg, context=None):
        res = {}
        for obj in self.browse(cr, uid, ids, context=context):
            result[obj.id] = False
            user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
            if user and user.sucursal_u:
                result[obj.id] = user.sucursal_u.id
        return res
    
        _columns = {            
                    'name': fields.char("Name", required=True),
                    'act_user_suc': fields.function(dame_usuario,
                        type='many2one', readonly = True, relation='sucursales'),
                    }