Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
16669 Переглядів

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?
Аватар
Відмінити

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

Найкраща відповідь

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

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лют. 25
5642
1
груд. 24
1302
1
лист. 22
15814
3
серп. 22
12752
2
серп. 22
4312