Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
16663 Tampilan

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
Buang

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

Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
2
Feb 25
5628
1
Des 24
1297
1
Nov 22
15810
3
Agu 22
12737
2
Agu 22
4307