Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
How to check availability of rooms under hotel management module?
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>
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.
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
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.
About This Community
This platform 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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 7/22/15, 3:21 AM |
Seen: 2440 times |
Last updated: 7/27/15, 6:05 AM |