我有一个带按钮的向导。在按钮操作上,我想运行报告并将PDF保留在服务器上。我有上面的代码片段,用于创建带有Web服务的报告。但是在向导环境中我通常只有uid(我认为)。
在向导中将报告提交到磁盘的等效方法是什么?
def reportToDisk(self, cr, uid, ids, context=None):
dbname = 'db'
username = 'user'
pwd = 'pass'
model = 'sale.order'
report_name = 'doc.sale'
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/object')
ids = sock.execute(dbname, uid, pwd, model, 'search',[])[0:1]
sock_report = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/report')
id_report = sock_report.report(
dbname, uid, pwd, report_name, ids,{'model': model, 'id': ids[0], 'report_type':'pdf'}
)
cont = True
while cont:
report = sock_report.report_get(dbname, uid, pwd, id_report)
cont = not report['state']
string_pdf = base64.decodestring(report['result'])
file_pdf = open('/home/arch-in/file.pdf','w')
file_pdf.write(string_pdf)
file_pdf.close()
答案 0 :(得分:1)
返回点击按钮时的报告操作(可以是向导按钮或查看按钮,只需按钮点击返回),如下所示:
def btn_clik_action(self, cr, uid, ids, context=None):
if context == None:
context = {}
value = {
'type': 'ir.actions.report.xml',
'report_name':'report.name.(servicename)',
'datas': {
'model':'model.name',
'id': ids and ids[0] or False,
'ids': ids and ids or [],
'report_type': 'pdf'
},
'nodestroy': True
}
只需返回报告操作即可为您提供报告文件,基本上您不需要编写任何内容。
感谢YOu