2016-05-16 3 views
1

QWebのレポートで「item」という要素を使用したいと思います。私は自分の報告書に何を書きますか? "item"はtabDataの属性です。あなたは私のpythonのコードを以下で見ることができます。 私はすでにレポートパーサーを構築しています。私のQWebレポートでpython関数を使用するには?

これは私のpythonのコードです:

def getLines (self, objects): 

      tabData = [] 
      print objects 
      for i in range (7): 
       tabData.append({}) 
       tabData [i] ['jour']  = self.tabJour [i] 
       tabData [i] ['commandes'] = {} 

      for o in objects: 
       indJour = int(o.jour) - 1 

       if indJour not in range(7): continue 

       commande = o.order_id.name 

       if not (tabData [indJour]['commandes'].has_key (commande)): 
        tabData [indJour]['commandes'][commande] = {} 
        tabData [indJour]['commandes'][commande]['items'] = [] 
        tabData [indJour]['commandes'][commande]['partner'] = o.order_partner_id.name 




       bois = o.bois1.code_fini 
       bois2 = o.bois2.code_fini 
       metal = o.metal.code_fini 
       tissus = o.tissu.code_fini 
       poignee = o.poignee.code_fini 
       patte = o.patte.code_fini 
       cfg  = o.config 


       optionTissu = o.tissu.couleur_finifr 

       qty   = int(o.product_uom_qty) 
       qtyEmballe = 0 
       qtyPeinture = qty - qtyEmballe - int(o.FabPeint) 
       qtyTeinture = qty - qtyEmballe - int(o.FabTeint) 
       qtyRembourage = qty - qtyEmballe - int(o.ProdFTissus) 
       qtyMetal  = qtyPeinture - int(o.ProdFMetal) 
       qtyBois  = qtyTeinture - int(o.ProdFBois) 

       if not (qtyMetal) or qtyMetal < 0: 
        qtyMetal = 0 
       if not (qtyBois) or qtyBois < 0: 
        qtyBois = 0 
       if not (qtyPeinture) or qtyPeinture < 0: 
        qtyPeinture = 0 
       if not (qtyTeinture) or qtyTeinture < 0: 
        qtyTeinture = 0 
       if not (qtyRembourage) or qtyRembourage < 0: 
        qtyRembourage = 0 

       if bois == '.': 
        bois = None 
       if bois2 == '.': 
        bois2 = None 
       if metal == '.': 
        metal = None 
       if tissus == '.': 
        tissus = None 
       if poignee == '.': 
        poignee = None 
       if patte == '.': 
        patte = None 
       if cfg == '.': 
        cfg = None 

       if optionTissu == "NONE": 
        optionTissu=None 

       tabData [indJour]['commandes'][commande]['items'].append ({ 
         'item': o.product_id.default_code, 
         'qty': qty, 
         'metal': metal, 
         'bois': bois, 
         'bois2': bois2, 
         'tissus': tissus, 
         'poignee': poignee, 
         'patte': patte, 
         'optionTissu': optionTissu, 
         'cfg': cfg, 
         'notes': o.notes, 
         'qtyEmballe': qtyEmballe, 
         'qtyMetal': qtyMetal, 
         'qtyBois': qtyBois, 
         'qtyPeinture': qtyPeinture, 
         'qtyTeinture': qtyTeinture, 
         'qtyRembourage': qtyRembourage, 
        }) 
      print "FIN" 
      return tabData 

はあなたの助けをいただき、ありがとうございます。

答えて

1

ただ、道の下には使用してPythonの辞書のあなたのリストを反復処理する必要があります。

あなたgetLinesを()メソッドは、辞書のリストとして返され、その後uがちょうど直接このようないくつかのものQwebのテンプレートにそのメソッドを呼び出すことができます。

辞書キーのご使用方法リストに基づいていますし、その値が自動的にあたりとして印刷されたのように、あなただけの直接承りKEY1、KEY2、...

<t t-foreach="getLines(o)" t-as="line"> 
     <tr> 
     <td><span t-esc="line.get('key1')"/> 
     </td> 
     <td> 
      <span t-esc="line.get('key2')"/> 
     </td> 
     </tr> 
</t> 

T-foreachの属性にそのメソッドを呼び出しますあなたの.py側に設定する

私の答えがあなたに役立つことを願っています:)

関連する問題