下面印刷qweb报告获取问题是我使用从向导打印报告的函数的代码..在odoo V8
class manager_monthly_salary_report_wizard(osv.osv_memory):
_name = "manager.monthly.salary.report.wizard"
_columns = {
'month': fields.integer("Month"),
'year': fields.integer("Year"),
}
def check_report(self, cr, uid, ids, context=None):
print "context -> ", context
print "ids -> ", ids
if context is None:
context = {}
self_read = self.read(cr, uid, ids)[0]
if (self_read['month'] >= 12 or self_read['month'] <= 0) and len(str(self_read['year'])) != 4:
raise osv.except_osv(_("Warning"),
_("You have invalid month/year ! please select correct one ... "))
else:
print "working normally ... "
if self_read['month'] in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
month_year = str("0" + str(self_read['month']) or self_read['month'])
elif self_read['month'] in [10, 11, 12]:
month_year = str(self_read['month'])
month_year = month_year + " - " + str(self_read['year'])
print "month_year ", month_year
departments = []
office_staff = []
for deprt in first_level_department_brws:
office_staff_ids = empl_obj.search(cr, uid, [('department_id', '=', deprt.id), '|', ('manager', '=', True), ('office_staff', '=', True)])
office_staff_brw = empl_obj.browse(cr, uid, office_staff_ids)
print " office_staff_brw ", office_staff_brw
department = {
'name': deprt.name,
'office_staff': office_staff
}
for dep_employee in office_staff_brw:
office_staff.append({
'name': dep_employee.name,...
})
department['office_staff'] = office_staff
print "office_staff -> ", office_staff
office_staff = []
departments.append(department)
print "Departments-> ", office_staff
department = {}
print "\n"
data = {
'ids': context.get('active_ids', []),
'model': context.get('active_model', 'ir.ui.menu'),
'form': departments
}
print "data -> ", data
print "__end__\n\n"
return self.pool['report'].get_action(cr, uid, [], 'custom_module.my_report', data=data, context=context)
报告XML文件的样子..
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="my_report">
<t t-call="report.html_container">
<div class="page">
<!--header -->
<!--<t t-call="report.internal_layout">-->
<!--content-->
<div class="row">
<span >"====="</span>
<span t-esc="Departments"/>
<t t-esc="data"/>
<t t-set="model" t-value="data['model']"/>
<t t-set="data" t-value="data['form']"/>
<t t-esc="data"/>
<span >"++++++"</span>
</div>
</div>
</t>
</template>
</data>
</openerp>
如果departmens
数据[“形式”]是一种字典,我是能够打印,但现在我已切换到列表和我是个让下面的错误,而打印报告
Traceback (most recent call last):
File "/home/demo/project/odoo/odoo_8/addons/report/controllers/main.py", line 120, in report_download
response = self.report_routes(reportname, converter='pdf', **dict(data))
File "/home/demo/project/odoo/odoo_8/openerp/http.py", line 410, in response_wrap
response = f(*args, **kw)
File "/home/demo/project/odoo/odoo_8/addons/report/controllers/main.py", line 65, in report_routes
pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context)
File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/demo/project/odoo/odoo_8/addons/report/models/report.py", line 192, in get_pdf
html = self.get_html(cr, uid, ids, report_name, data=data, context=context)
File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/demo/project/odoo/odoo_8/addons/report/models/report.py", line 167, in get_html
return particularreport_obj.render_html(cr, uid, ids, data=data, context=context)
File "/home/demo/project/odoo/odoo_8/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/demo/project/odoo/odoo_8/addons/report/models/abstract_report.py", line 35, in render_html
if data and data.get('form', {}).get('landscape'):
AttributeError: 'list' object has no attribute 'get'
在PY代码
更新
我刚才改为
data = {
'ids': context.get('active_ids', []),
'model': context.get('active_model', 'ir.ui.menu'),
'form': {'departments': departments}
}
,并且正在打印报表....现在的问题是,为什么他们不能直接打印报告,如果我使用
data = {
'ids': context.get('active_ids', []),
'model': context.get('active_model', 'ir.ui.menu'),
'form': departments
}
list代替字典在data['form']
...?
谢谢,但是,这是我的格式是 '数据= { '形式':[{ 'A':1, 'B':[{..}]},{ 'A':1 ,'b':[{..}]},..]' 和我刚刚尝试打印的数据['form']'这是一个列表,不访问任何元素... '...用你的例子我只是试图打印'form',然后才能做''...... –
Bhuro
使用t-raw,看看我的编辑 –
同样的错误......'<! - < t t-esc =“data”/> - > <! - - ><! - - - ><! - - >'... –
Bhuro