m3asmi
m3asmi

Reputation: 1262

how to add a related field many2one?

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?

Upvotes: 1

Views: 2666

Answers (2)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

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

Upvotes: 3

Hardik Patadia
Hardik Patadia

Reputation: 1999

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

Upvotes: 3

Related Questions