Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to check availability of rooms under hotel management module?

By
Kapil More
on 7/22/15, 3:21 AM 1,195 views


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>

0
David Bertha
On 7/22/15, 5:06 AM

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.

Okey David. Thanks, I will try it.

Kapil More
on 7/23/15, 1:39 AM

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?

Kapil More
on 7/23/15, 4:10 AM

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

David Bertha
on 7/23/15, 5:29 AM
0
Kapil More
On 7/27/15, 6:00 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/22/15, 3:21 AM
Seen: 1195 times
Last updated: 7/27/15, 6:05 AM