This question has been flagged
2 Replies
5977 Views

I have three model as follows:

room (model.model):

_name=hotel.room

name = fields.Integer(string = 'Room Number')
room_type = fields.Many2one('hotell.roomtype', string='Room Type')

roomtype(model.model):

_name = 'hotell.roomtype'
   
    name = fields.Selection([('Standard', 'Standard'), ('Deluxe', 'Deluxe')], string = 'Room Type')
    room_ppn = fields.Integer(string = 'Price per Night')

reservation(model.model):

_name = 'hotell.reservation'

room_id = fields.Many2one('hotell.room', string='Room Number')

ppn = fields.Integer(string="Price per Night")


How can I get the price per night from model roomtype via model room?

(P.S there's no relation allowed between model reservation and roomtype

Avatar
Discard
Best Answer

use related : https://www.odoo.com/documentation/11.0/reference/orm.html

Avatar
Discard
Best Answer

Hi,

You can use a related field concept here:

class HotelRoom(models.Model):
_name = 'hotel.room'

name = fields.Integer(string='Room Number')
room_type = fields.Many2one('hotell.roomtype', string='Room Type')
price = fields.Integer(string='Price per Night', related='room_type.room_ppn')

Thanks

Avatar
Discard