콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
16751 화면

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

아바타
취소
관련 게시물 답글 화면 활동
2
2월 25
5899
1
12월 24
1450
1
11월 22
15962
3
8월 22
12984
2
8월 22
4475