python - 如何在odoo 8中获取pdf数据或内容

标签 python python-2.7 odoo odoo-8 qweb

这两天一直卡在修复问题。我想获取 pdf 文件的二进制数据或内容,并将其保存在一个变量中,无论是否将 pdf 文件发送给用户。这是我的代码:

def generate_printout(self):

    data = self.read([self.id])[0]        
    datas = {
        'ids': [],
        'model': 'monthly.bill.wizard', # wizard model name
        'form': data,
        'context':self.env.context
    }

    # -------- HOW TO GET THE CONTENT OF PDF FILE -------- 

    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'ig_bill.monthly_bill_printout_report_template',#module name.report template name
        'datas': datas,
    }   

    # -------- HOW TO GET THE CONTENT OF PDF FILE --------

这些是解析器类

class monthly_bill_report(osv.AbstractModel):
    _name = 'report.ig_bill.monthly_bill_printout_report_template'
    _inherit = 'report.abstract_report'
    _template = 'ig_bill.monthly_bill_printout_report_template'
    _wrapped_report_class = monthly_bill_printout_report_parser


class monthly_bill_printout_report_parser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context): 
        super(monthly_bill_printout_report_parser, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,            
            'parameter_contact' : self._get_contact,
            etc...
        })

最佳答案

您可以使用以下方法获取它。

report_name = 'external_id_of_your_report'
datas=self.env['report'].get_pdf(self, report_name)

You can get report data using get_pdf method which is available in report module.

In which you need to pass report name.

这可能对你有帮助。

关于python - 如何在odoo 8中获取pdf数据或内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45188215/

相关文章:

python - 定义您自己的 python 对象和数据类型

python-2.7 - Odoo on write() 方法检查多对多关系

odoo - 我如何在 OpenERP 6.1 中共享 "advanced filters"?

python - 工作流程按钮 Odoo v8

pdf - QWeb pdf 报告 odoo 10

javascript - 使用 javascript 解析时间戳响应文件 (tsr)

python - 如何使用 python 脚本或任何命令在 hyper-v 上使用 WMIC 创建虚拟机?

python - 从 GLCM 中提取 Haralick 特征。为什么我会为每个功能获取多个值?

python - 在python中访问多维字典时,如何返回默认值而不是键错误?

Python返回最近30天的数据