Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
6 Odgovori
9327 Prikazi


Hi, For Hotel Management module, I want to add functionality for checking availability of rooms between two dates that is, start date and end date by the given type.

Inside of form view I want to show Start Date and End Date then below that Room Type and after that, available rooms between two dates. Can anyone help me to check and then display the rooms available between two dates?

Here is my code,

class hotel_roomsavail(osv.Model):

_name = "hotel.roomsavail"

_columns = {

'check_in':fields.datetime('Check In Date', required=True),

'check_out': fields.datetime('Check Out Date', required=True),

'name':fields.char('Name', size=64),

#'state': fields.selection([('assigned', 'Assigned'), ('unassigned', 'Unassigned')], 'Room Status'),

'cust_reservation_id': fields.many2one('hotel.reservation', 'Reservation'),

'cat_id': fields.many2one('product.category', 'Room Type', domain="[('isroomtype','=',True)]", change_default=True),

#'pricelist_id':fields.many2one('product.pricelist', 'Price List', required=True, readonly=True, states={'draft':[('readonly', False)]}, help="Pricelist for current reservation. "),

#'room_reserved':fields.many2many('hotel.room', 'hotel_reservation_line_room_rel', 'room1_id', 'hotel_reservation_line_id', domain="[('isroom','=',True),('cat_id','=',cat_id)]"),

'room1_id': fields.many2one('hotel.room', 'Room id'),

#'rooms':fields.many2one('hotel.room', 'room_reservation_line_ids'),

}

The form view will be,

<record model="ir.ui.view" id="view_hotel_roomsavail_form">

<field name="name">hotel.roomsavail.form</field>

<field name="model">hotel.roomsavail</field>

<field name="arch" type="xml">

<form string="Rooms Availability" version="7.0">

<group colspan="4" col="4">

<field name="check_in"/>

<field name="check_out"/>

</group>

<separator string="Room Type"/>

<field name="name" invisible="1" />

<field name="cat_id" on_change="on_change_cat(cat_id, parent.check_in, parent.check_out)" select="1" colspan="4" nolabel="1"/>

<newline/>

<!-- <field name="cat_id"/> -->

<!-- <field name="room_id"/> -->

<!--<separator string="Rooms"/>

<field name="room1_id" colspan="4" string="Room Number" nolabel="1" />

</form> -->

<separator colspan='4' string="Check Room Availability" />

<tree>

<field name="room1_id" colspan="4" string="Rooms"/>

<!-- <field name="check_in"/> -->

<!-- <field name="check_out"/> -->

<!-- <field name="state"/> -->

<!-- <field name="cust_reservation_id" colspan="4" string="Customer Reservation"/> -->

</tree>

</form>

</field>

</record>

Avatar
Opusti
Best Answer

You can try with a fields.function that generate a one2many relationship.

API V7 way :

def _get_available_rooms(self, cr, uid, ids, name, args, context=None) :
    res = {}
    for roomavail in self.browse(cr, uid, ids, context=context) :
        search_domain = ...
        room_available_ids = self.pool.get('hotel.room').search(cr, uid, search_domain, context=context)
        res[roomavail.id] =  room_available_ids
    return res
'available_room_ids' : fields.function(_get_available_rooms, type='one2many', relation='hotel.room')

You can also define a search view with a filter.

Avatar
Opusti
Avtor

Okey David. Thanks, I will try it.

Avtor

Hey David, for the search domain, I added like this fields.Many2one('hotel.roomsavail', string="Available Rooms", domain="[('product_id','=',order_id)]") but error out for 'not defined _get_available_rooms'. Can you elaborate that what should I exactly add to?

You should declare _get_available_rooms before (in the code text) referencing it in your field definition

Avtor Best Answer

def _get_available_rooms(self, cr, uid, ids, name, args, context=None) :

res = {}

for roomavail in self.browse(cr, uid, ids, context=context) :

search_domain = "[('product_id','=','order_id')]"

room_available_ids = self.pool.get('hotel.room').search(cr, uid, search_domain, context=context)

res[roomavail.id] = room_available_ids

return res

_columns = {
'rooms': fields.many2one('hotel.room.reservation.line', 'Rooms'),
'check_in':fields.datetime('Check In Date', required=True),
'check_out': fields.datetime('Check Out Date', required=True),
'product_id': fields.many2one('product.product', 'Room Number', required=True, ondelete='cascade'), 'status':fields.selection([('available', 'Available'), ('occupied', 'Occupied')], 'Status'),
'room_no':fields.many2one('hotel.room', 'Room No', required=True),
'available_room_ids' : fields.function(_get_available_rooms, type='one2many', relation='hotel.room'),

I declared _get_available_rooms before referencing field. But, there is no any such output that shows rooms avaiable as per the date scheduled.

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
apr. 24
2247
4
nov. 23
6454
1
nov. 23
2218
0
okt. 23
2172
0
dec. 22
2986