Skip to Content
Menu
This question has been flagged
1 Reply
15662 Views

II have 2 models: CinemaSeat and BookingTicket. Here are my code:

class CinemaSeat(models.Model):

    _name = 'cinema.seat'

    seat_number = fields.Integer("Seat Number")

    movie = fields.Char("Movie name")

    date = fields.Date("Performance date")

    status = fields.Selection([("1", "empty"), ("2", "reserved")])

    booking_ids = fields.One2many("booking.ticket", "booking_seat", string="Booking ID")


class BookingTicket(models.Model):

    _name = 'booking.ticket'

    id = fields.Char("Booking ID")

    name = fields.Char("Customer name")

    mobile = fields.Char("Mobile number")

    booking_seat = fields.Many2one("cinema.seat", string="Seat ID")

Currently the booking_seat only show "cinema_seat, 1". How can I set it to show the value of seat_number instead?
Avatar
Discard

How to show two different values in many2one field in Odoo: https://goo.gl/8tYbcU

Best Answer

Hi Nguyen,

This is because your model cinema.seat has no field name.
By default Odoo will build the name that is shown in a many2one with the field 'name'.
If you don't have a field named 'name' you'll need to define your own with the _rec_name parameter though.
Just add it to your cinema.seat model like this:

class CinemaSeat(models.Model):
    _name = 'cinema.seat'
    _rec_name = 'seat_number'

If you want to go further and build a whole custom title you can do it too. You just need to add a function "name_get" to build your own name then. For example:

@api.multi
def name_get(self):
    result = []
    for record in self:
        record_name = record.movie + ' - ' + record.seat_number
        result.append((record.id, record_name))
    return result

Regards,
Yenthe

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
14645
3
Aug 22
10751
2
Aug 22
3045
0
Jul 22
835
2
Oct 21
1433