简体   繁体   English

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

[英]how to call qweb report in another model in odoo?

I have created a wizard in the that using many2one field of another model. 我在另一个模型的many2one字段中创建了一个向导。 where the qweb-report has been mentioned. 提到qweb-report的地方。 Now I want to select 1record(from many2one field) and print the respective report.[previously i've done invoice printing in that menu's form view.] . 现在,我想选择1record(从many2one字段中)并打印相应的报告。[以前,我已经在该菜单的窗体视图中完成了发票打印。] sometimes here empty report is getting prints.Can anybody please explain it clearly?here is my code. 有时这里有空报告正在打印。有人可以清楚解释吗?这是我的代码。

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

I'm getting this error: 我收到此错误:

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__'

thanks in advance..!! 提前致谢..!!

You can try this code: 您可以尝试以下代码:

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

If you use self.pool then write self.pool['module name'] and if you use self.pool.get then self.pool.get('module name') 如果使用self.pool,则编写self.pool ['module name'];如果使用self.pool.get,则编写self.pool.get('module name')

May be this is help you. 可能这对您有帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM