【问题标题】:Sort by date ASC in qweb report odoo在 qweb 报告 odoo 中按日期 ASC 排序
【发布时间】:2017-07-06 07:30:21
【问题描述】:

我想按日期升序对我的 qweb 报告中的数据进行排序。

我的例子:

<t t-foreach="doc.line_ids" t-as="o"> 
   <tr>
       <td class="text-right">
           <span t-field="o.date"/>
        </td> 
   </tr>
</t>

【问题讨论】:

    标签: openerp odoo-9 odoo-10


    【解决方案1】:

    我已经用下面的代码解决了这个问题:

    <t t-foreach="doc.line_ids.sorted(key=lambda x: x.date)" t-as="o"> 
       <tr>
           <td class="text-right">
               <span t-field="o.date"/>
            </td> 
       </tr>
    </t>
    

    【讨论】:

      【解决方案2】:

      你好 user_odoo,

      排序()
      返回按提供的键函数排序的记录集。如果没有提供键,则使用模型的默认排序顺序:

      #sort records by name
      records.sorted(key=lambda r: r.name)
      

      排序(key=None,reverse=False)
      返回键自排序的记录集。

      Parameters
      key -- 一个参数的函数,它返回每个记录的比较键,或者 None,在这种情况下,记录根据默认模型的顺序
      reverse -- 如果为True,则以相反的顺序返回结果

      您的问题解决方案如下代码尝试,

      <tr t-foreach="doc.order_line.sorted(key=lambda record: record.name, reverse=False)" t-as="ol"> 
          <td class="text-right">
              <span t-field="ol.name"/>
          </td>
          ...
      </tr>
      

      希望我的回答对你有所帮助。
      如果有任何疑问,请。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多