Skip to Content
Menu
This question has been flagged
2 Replies
16595 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
Best Answer

For the user who are using latest version of odoo


By default, Odoo allows searching customers only by name and displays only the name in Many2One fields. This module enhances the Many2One search and display functionality by enabling users to search using multiple fields (Phone, Email, Mobile, etc.) and display multiple values directly inside the Partners Many2One selection.

https://apps.odoo.com/apps/modules/17.0/mh_partner_search_and_display_multiple_field

Avatar
Discard
Related Posts Replies Views Activity
2
Feb 25
5484
1
Dec 24
1209
1
Nov 22
15723
3
Aug 22
12571
2
Aug 22
4207