2017-02-01 9 views
1

どのようにSUMを追加しますか?qwebレポートで合計を追加

    <table class="table table-condensed"> 
         <thead> 
          <tr> 
           <th>ID</th> 
           <th>Name</th> 
           <th>Quantity</th> 
          </tr> 
         </thead> 
         <tr> 
          <t t-foreach="docs" t-as="o"> 
           <tr> 
            <td><t t-esc="o.id"/></td> 
            <td><t t-esc="o.name"/></td> 
            <td><t t-esc="o.quantity"/></td> 
           </tr> 
          </t> 
         </tr> 
         <tr> 
          <td colspan="3" class="text-right"> SUM (o.quantity) </td> 
         </tr> 
        </table> 

この状況では可能ですか?

答えて

2

ループの繰り返しごとに1つの変数と合計数量を作成し、最後に印刷することができます。

だから、次のように試してみてください:コードの下

<table class="table table-condensed"> 
    <t t-set="qty" t-value="0"> 
    <thead> 
     <tr> 
      <th>ID</th> 
      <th>Name</th> 
      <th>Quantity</th> 
     </tr> 
    </thead> 
     <tr> 
      <t t-foreach="docs" t-as="o"> 
      <tr> 
       <td><t t-esc="o.id"/></td> 
       <td><t t-esc="o.name"/></td> 
       <td><t t-esc="o.quantity"/></td> 
       <t t-set="qty" t-value="qty + o.quantity"/> 
      </tr> 
      </t> 
      </tr> 
      <tr> 
       <td colspan="3" class="text-right"> <span t-esc="qty"></span> </td> 
      </tr> 
</table> 
1

試して

<table class="table table-condensed"> 
        <thead> 
         <tr> 
          <th>ID</th> 
          <th>Name</th> 
          <th>Quantity</th> 
         </tr> 
        </thead> 
        <tr> 
         <t t-foreach="docs" t-as="o"> 
          <tr> 
           <td><t t-esc="o.id"/></td> 
           <td><t t-esc="o.name"/></td> 
           <td><t t-esc="o.quantity"/></td> 
          </tr> 

         </t> 
        </tr> 
        <tr> 
         <span t-esc="sum(line.quantity for line in docs)"/> 
        </tr> 
       </table> 
関連する問題