콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
4569 화면

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),

}


아바타
취소
베스트 답변

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.

아바타
취소
베스트 답변

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."))

아바타
취소
베스트 답변

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.

아바타
취소
작성자 베스트 답변

@prasanth: thanks prasanth. its working perfectly

아바타
취소
관련 게시물 답글 화면 활동
0
2월 21
4040
0
2월 18
3036
3
6월 17
6118
0
1월 16
3966
2
8월 19
4885