Skip to Content
Menu
This question has been flagged
4 Replies
11651 Views

Hi, am unable to get movie names in field.many2one. 

class tickets(osv.osv):

_name = 'tickets.book'

_description = 'tickets'

_columns={

'movie':fields.selection([('1', 'X-Men'),('2', 'Transporter'),('3', 'Salt'),('4', 'Taken')],'Movie Title',required=True),

'date':fields.date('Date',required=True),

'x_seat':fields.integer('Seats:',size=128,required=True),

'theater':fields.selection([('imax', 'Imax'),('inox','Inox'),('pvr','Pvr')],'Theater',required=True),

'time':fields.selection([('10:00am', 'Morning Show'),('06:00Pm', 'First Show')],'Time',required=True),

}

class tickets_amount(osv.osv):

_name = 'tickets.amount'

_description = 'tickets amount'

def _sel_func(self, cr, uid, context=None):

obj = self.pool.get('tickets.book')

ids = obj.search(cr, uid, [])

res = obj.read(cr, uid, ids, ['name', 'id'], context)

res = [(r['id'], r['name']) for r in res]

return res

_columns={

'date':fields.date('Date',required=True),

'x_amount':fields.float('Amount',required=True),

'movie':fields.many2one('tickets.book','Movie',required=True),

}

 

Avatar
Discard
Best Answer

Getting value from selection field you can try this,

value = dict(browse_obj._columns['selection field'].selection).get(browse obju.selection field name)

Hope this will useful to you.

Thanks.

Shamji

Avatar
Discard
Best Answer

Many2one display "name" field value or _rec_name = "field_name"

In your case use _rec_name,

Example,

class tickets(osv.osv):

_name = 'tickets.book'

_description = 'tickets'

_rec_name = "movie"

Avatar
Discard
Best Answer

Thank you your way is very good

Avatar
Discard
Best Answer
def get_selection_label(self, object, field_name, field_value):
  return dict(self.env[object].fields_get(allfields=[field_name])[field_name]['selection'])[field_value]


class ResPartner(models.Model):
  _inherit = 'res.partner'

    def my_method(self):
        state_value_translated = get_selection_label(self, 'res.partner', 'state', self.state)

Avatar
Discard