1
votes

I have a field on stock_picking table I would like to relate it with stock_move

 _inherit= 'stock.picking' 
 _columns={
        'user_id': fields.many2one('res.users', 'user', select=True),
}

I would like to relate the field user_id with stock_move
I tried this

 _inherit= 'stock.move' 
 _columns={
  'user_id': fields.related('picking_id', 'user_id', relation="res.users", type='many2one', string="user", store=True, readonly=True)
}

any Idea brothers?

2

2 Answers

3
votes

You have used wrong model in inherit it should be as follows:

 _inherit= 'stock.picking' 
 _columns={
        'user_id': fields.many2one('res.users', 'user', select=True),
}

 _inherit= 'stock.move' 
 _columns={
  'user_id': fields.related('picking_id', 'user_id', relation="res.users", type='many2one', string="user", store=True, readonly=True)
}
3
votes

Agree with @Hardik Patadia. But you may also try with type=char

_inherit= 'stock.picking' 
_columns={
    'user_id': fields.many2one('res.users', 'user', select=True),
}

_inherit= 'stock.picking.in' 
_columns={
    'user_id': fields.many2one('res.users', 'user', select=True),
}

_inherit= 'stock.picking.out' 
_columns={
    'user_id': fields.many2one('res.users', 'user', select=True),
}

_inherit= 'stock.move' 
_columns={
    'user_id': fields.related('picking_id', 'user_id', 'name', type='char', string='User', store=True, readonly=True ), 
}

Here is an example