Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get names from field.selection

By
joshi
on 4/28/15, 9:45 AM 1,194 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),

}

 

2

Solanki Shamji

--Solanki Shamji--
1293
| 5 2 6
Baroda, India
--Solanki Shamji--

Hello!

Solanki Shamji
On 4/29/15, 2:03 AM

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

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 4/29/15, 1:33 AM

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"

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/28/15, 9:45 AM
Seen: 1194 times
Last updated: 4/29/15, 2:03 AM