2015-07-22 68 views
0

如何從報告模板傳遞文檔到解析器類,這樣我可以修改報告如何將文檔從模板傳遞給解析器類?

class purchase_report(report_sxw.rml_parse): 
    def __init__(self, cr, uid, name, context): 
     super(purchase_report, self).__init__(cr, uid, name, context=context) 
     self.localcontext.update({ 
      'time': time, 
      'get_purchase': self.get_purchase, 
      }) 

    def get_purchase(self): 
     cr = self.cr 
     uid = self.uid 
     purchase_obj=self.pool.get('purchase.order') 
     ids = purchase_obj.search(cr, uid, []) 
     records = purchase_obj.browse(cr, uid, ids) 
     print "yes" 
     return record 

我的模板

<template id="report_wizard"> 
    <t t-call="report.html_container"> 
     <t t-foreach="docs" t-as="doc"> 
     <t t-call="report.external_layout"> 
     <div class="page"> 
      <div class="oe_structure" /> 
        <td> 
         <strong>Purchase Order: 
         <t t-set="records" t-value="get_purchase()"/> 
         <table> 
          <thead> 
           <th>Reference</th> 
           <th>Order Date</th> 
          </thead> 
          <tbody> 
           <tr t-foreach="records" t-as="record"> 
            <tr t-if = "record.partner_id.name == doc.customer.name"> 
             <td><span t-esc="record.name"/> </td> 
             <td><span t-esc="record.date_order"/></td> 
            </tr> 
          </tr> 
          </tbody> 
         </table> 
        </strong> 
        </td> 
      </div> 
     </t> 
    </t> 
    </t> 
</template> 

,現在我有我在此模板文檔嚮導。我需要在我上面提到的解析器類中的文檔。 如何得到它?

+0

需要一個函數,應該在模板中調用。問題解決了我 –

回答

1

模板通docs在函數調用:

<t t-set="records" t-value="get_purchase(doc)"/> 

而且趕上你的功能:

高清get_purchase(個體經營,文檔):

這會讓你有記錄正在打印。此外,文檔默認是您的self.localcontext中的關鍵,因此您可以隨時從localcontext獲取文檔密鑰。

最好,

+0

謝謝....但你實際上遲到了..... –

相關問題