2017-07-19 29 views
3

我一直被困在兩天內解決問題。我想獲取PDF文件的二進制數據或內容,並將其保存在一個變量中,無論是否將pdf文件傳給用戶。這裏是我的代碼:如何獲得pdf數據或odoo 8中的內容

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... 
     }) 

回答

3

您可以通過以下方法得到它。

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

可以使用get_pdf方法,它是在 報告模塊可讓報表數據。

其中您需要傳遞報告名稱。

這可能對你有幫助。

+0

謝謝Empiro Technologies Pvt。公司 –