Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
4352 Vistas

i have one problem , i have one class named as room details and second one is room booking. we can go to book a room by room booking model. I want to create a constraint to it . Problem is that if one person can book one room at one date&time if second person can book that room may be after that time or before that time.previously i askd this question , and there are some answers also i got but i cant figure it out.I cant able to find out the solution fromr that, please help me.

i will give my code


class room_management(osv.Model):

_name = 'room.management'

_columns = {

'name': fields.char('Name',requierd=True, help='Put a Name for your Room example: Interview room,board room,conference Hall...etc '),

'location':fields.char('Location',requierd=True,help="give the location as city name or street name..etc"),

'floar':fields.char('Floor Details',help='Enter the Foar no or name,like Foar 4B6 or somthing should identification'),

'address':fields.text('Address',requierd=True,help='Detailed Address'),

'no_seats':fields.integer('No of Seats',requierd=True,help='Number of seats occupied in this room'),

'room_no':fields.char('Room No',requierd=True,help='Should be unique',),

}


class room_booking(osv.Model):

_name = 'room.booking'

_columns = {

'room_id' : fields.many2one('room.management', string="Room Booking"),

'duration': fields.integer('Duration'),

'reason': fields.char('Reason',requierd=True ,help="short deatails about booking,Example:Simons Hr interview"),

'start': fields.datetime('Start At',requierd=True),

'end': fields.datetime('End At',requierd=True),

}


Avatar
Descartar
Mejor respuesta

Hello Logicious,

This kind of constraints are applicable for creation but also for edition. If you really want to perform input validation overwriting `create` also overwrite `write` as well.

A cleaner solution to cover both cases is to create Python based constraints like the one you can see in `hr_holidays`, please see here:

https://github.com/odoo/odoo/blob/8.0/addons/hr_holidays/hr_holidays.py#L208

* https://github.com/odoo/odoo/blob/8.0/addons/hr_holidays/hr_holidays.py#L152

Constraints are automatically invoked during creation or edition:

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L3949 

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L4273 

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L1239 

Please also note tha Odoo 8 introduced a new way to declare constraints (and deprecated the above):

https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model._inherits

https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.api.constrains

Regards.

Avatar
Descartar
Mejor respuesta

you just try this i think its will work fine as your wish :-

def create(self, cr, uid, vals, context=None):

all_room_ids=self.search(cr,uid,[('room_id','=',vals['room_id'])])

for room_id in all_room_ids     

       room_data=self.browse(cr,uid,room_id)          

                      if ((vals['start'] >= room_data.start) and (vals['end'] <= room_data.start)) or (vals['start'] >= room_data.end):

                                  print'yyyyyyyyyyyyy',room_data

                      else:

                              raise osv.except_osv(_('Error!'),_("Room Already booked."))

Avatar
Descartar
Mejor respuesta

Hi,

You should make room booking constraints on the basis of room status Or you can create warning if it already booked.

May it will help you.

Avatar
Descartar
Autor Mejor respuesta

@prasanth: thanks prasanth. its working perfectly

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
feb 21
3618
0
feb 18
2833
3
jun 17
5684
0
ene 16
3678
2
ago 19
4372