A. Chandu A. Chandu - 3 months ago 17
Python Question

How to pass field values of custom model to Qweb report?

I have created a wizard in that i placed a many2one field [names] from another model in which report printing is enabled. What is happening here is when i select one record & clicked on print button it is printing only empty report.so is it possible to fetch the data into report over here.

def print_report(self, cr, uid, ids, context=None):

ob=self.pool.get('book.room')
wizard=self.browse(cr,uid,ids,context=context)


datas = {
'ids': wizard.name,
'model': 'book.room',
'form': ob.browse(cr, uid, wizard.name)#[-1]
# 'form': [{'create_uid': (1, u'Administrator'), 'create_date': '2015-10-20 10:32:42', 'name': (1, u'Nani'), '__last_update': '2015-10-20 10:32:42', 'date_end': '12/10/2015', 'date_start': "13/12/1201", 'write_uid': (1, u'Administrator'), 'write_date': '2015-10-20 10:32:42', 'display_name': u'Nani', 'id': 18}]
}

print datas.get('form')

# print datas,'88888888888888'
# print datas['form'],'9999999999999'

return {
'type': 'ir.actions.report.xml',
'report_name': 'hotel_mng.Booking_Details',
'datas': datas,
}


Thanks in advance

Answer
 class print_report(osv.TransientModel):
_name='report.wizard'
_columns={
    'room1':fields.many2one('hotel.allroom','roomnum','Room No.')
}
    def print_report(self, cr, uid, ids, context=None):
        current=self.browse(cr,uid,ids)
        obj=self.pool.get('book.room')
        k=obj.search(cr,uid,[('name','=',current.name.name)],context=context)


    context = {}
    data = self.read(cr, uid, ids)[0]


    datas = {
    'ids': k,
    'model': 'report.wizard',
    'form': data,
    'context':context
    }
    return{
        'type' : 'ir.actions.report.xml',
        'report_name' : 'hotel_mng.Booking_Details',
        'datas' : datas,
        } 

print_report()

the above code is working fine for me.. it takes names from ref. model and prints report Thanks