如何在odoo的另一个模型中调用qweb报告?

时间:2015-10-27 12:14:10

标签: python xml openerp odoo qweb

我使用另一个模型的many2one字段创建了一个向导。提到qweb报告的地方。现在我想选择1record(来自many2one字段)并打印相应的报告。[之前我已在该菜单的表单视图中进行了发票打印。]。有时这里空的报告正在打印。有人可以清楚解释一下吗?这是我的代码。

class invoice_wizard(osv.TransientModel):
_name = 'invoice.wizard'

_columns = {

    'name':fields.many2one('hotel.booking',string="CustomerName"),

    }

def invoice_print(self,cr,uid,ids,vals,context=None):
    bookz=self.browse(cr,uid,ids,context=context)
    ids2=self.pool.get['book.room'].search([('name','=',bookz.name.name)])


    data = {
        'ids': ids2,
        'model': 'book.room',
        'form': self.env['book.room'].read(['name'])[0]
    }

    return self.env['report'].get_action(self, 'hotels.Booking_Details',
                                         data=data)

invoice_wizard()  

我收到了这个错误:

Traceback (most recent call last):
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 537, in    _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/home/anipr/Desktop/odoo-8.0/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/home/anipr/Desktop/odoo-8.0/openerp/addons/web/controllers/main.py", line 952, in call_button
action = self._call_kw(model, method, args, {})
File "/home/anipr/Desktop/odoo-8.0/openerp/addons/web/controllers/main.py", line 940, in _call_kw
return checked_call(request.db, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/addons/web/controllers/main.py", line 939, in checked_call
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/anipr/Desktop/odoo-8.0/openerp/addons/hotels/wizard/hotel_wizard.py", line 50, in invoice_print
ids2=self.pool.get['book.room'].search([('name','=',bookz.name.name)])
TypeError: 'instancemethod' object has no attribute '__getitem__'

提前谢谢.. !!

2 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

class invoice_wizard(osv.TransientModel):
_name = 'invoice.wizard'

_columns = {

    'name':fields.many2one('hotel.booking',string="CustomerName"),

    }

def invoice_print(self,cr,uid,ids,vals,context=None):
    bookz=self.browse(cr,uid,ids,context=context)
    ids2=self.pool.get('book.room').search([('name','=',bookz.name.name)])


    data = {
        'ids': ids2,
        'model': 'book.room',
        'form': self.env['book.room'].read(['name'])[0]
    }

    return self.env['report'].get_action(self, 'hotels.Booking_Details',
                                         data=data)

invoice_wizard()  

如果您使用self.pool,则编写self.pool ['模块名称'],如果您使用self.pool.get,则使用self.pool.get('模块名称' )

可能这对你很有帮助。

答案 1 :(得分:0)

class report_wizard(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('hotel.book')
    k=obj.search(cr,uid,[('room','=',current.room1.roomnum)],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' : 'hotels.Booking_Details',
        'datas' : datas,
        } 

report_wizard()