Odoo Help

0

0
6 Answers
0
David Bertha
22/07/15, 05:06

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.

3 Comments
Kapil More
23/07/15, 01:39

Okey David. Thanks, I will try it.

Kapil More
23/07/15, 04:10

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?

David Bertha
23/07/15, 05:29

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

0
Kapil More
27/07/15, 06:00

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.

Ask a Question
Writer
Keep Informed
1 follower(s)
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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now