This question has been flagged

Hello,

I managed to display the theaders but the tbody isn't.

This is my xml:

<tbody>
 <t t-set="pickings" t-value="o.get_pickings(date_start, date_end)" />
  <t t-foreach="pickings" t-as="pick">
  <t t-set="line_items" t-value="o.get_line_items(pick)">
  <t t-foreach="line_items" t-as="line">
  <p>Hello, this is a test paragraph</p>
  <tr>
          <td><span t-esc="line.partner_id.name " /></td>
  <td><span t-esc="line.invoice.name" /></td>
  <td><span t-esc="line.product_name" /></td>
  <td><span t-esc="line.qty_done" /></td>
  </tr>
  </t>
  </t>
  </t>
 </tbody>


.py

 @api.multi
    def get_line_items(self, picking_id):
        line_items = picking_id.pack_operation_ids
        items = []
        for item in line_items:
            items.append({"product_name": item.product_id.name, "done_qty": item.qty_done, 
                          "si_number": " ".join([ invoice.name for invoice in picking_id.sale_id.invoice_ids]),
                          "partner_name": picking_id.partner_id.name })
        
        print(items)
        return items




result:
[{'partner_name': u'Happy', 'done_qty': 1.0, 'product_name': u'Noodles', 'si_number': ''}] [{'partner_name': u"Mimi", 'done_qty': 10.0, 'product_name': u'Rice', 'si_number': u'SI# 1121245'}] [{'partner_name': u"Mimi", 'done_qty': 10.0, 'product_name': u'Shampoo', 'si_number': u'SI# 1121246'}]
Avatar
Discard
Best Answer

Your code looks good except the for loop of the line which is inside the t-set and also the code inside the loop should handle the JSON data.

Try the following code:

    <t t-set="line_items" t-value="o.get_line_items(pick)"/>

<t t-foreach="line_items" t-as="line">
<p>Hello, this is a test paragraph</p>
<tr>
<td><span t-esc="line.get('partner_name')" /></td>
<td><span t-esc="line.get('si_number')" /></td>
<td><span t-esc="line.get('product_name')" /></td>
<td><span t-esc="line.get('done_qty')" /></td>
</tr>
</t>
Avatar
Discard
Author

Thanks, it works.