从向导运行报告 [英] Run a report from a wizard

查看:19
本文介绍了从向导运行报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带按钮的向导。在按钮操作上,我想运行报告并将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()

推荐答案

返回您点击按钮时的报表动作(可以是向导按钮,也可以是视图按钮,只与点击返回按钮配合使用),如下所示:

  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
       }

只需返回报告操作即可为您提供基本上不需要编写的报告文件。

谢谢

这篇关于从向导运行报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆