This question has been flagged
4 Replies
10483 Views

I want to show data like this:

No | Code | Brand | Cost 
------------------------
 1 |  201 |       |
------------------------
   |      |   A   | 200
   |      |   B   | 350
------------------------
 2 |  202 |       |
------------------------
   |      |   C   | 100
   |      |   D   | 110


This is my code in py and xml:

Code in py:

report=self.env['report']
document=self._get_pos_report_one(data)
docss=self._get_pos_report_two(data)
ctx=self._context.copy()
object=self.env['report.wizard'].browse([ctx['active_id']])
data={'o':object,
      'docs':document,
      'docss':docss}
return report.render('report.report_sales', data)

Code in xml:

<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
    <td class="pb_text_center line_left">                                   
        <t t-set="num" t-value="num + 1"/>
        <t t-esc="num"/>
    </td>
    <td class="pb_text_left line_left">
        <span t-esc="row['code']"/>
    </td>

    <tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
        <td class="pb_text_center line_left">
        </td>
        <td class="pb_text_left line_left">
        </td>
        <td class="pb_text_left line_left">
            <span t-esc="row_detail['brand']"/>
        </td>
        <td class="pb_text_left line_left">
            <span t-esc="row_detail['cost']"/>
        </td>
    </tr>
</tr>

This is current result with my code (py and xml):

No | Code | Brand | Cost 
------------------------
 1 |  201 |       |
------------------------
   |      |   A   | 200
   |      |   B   | 350
   |      |   C   | 100
   |      |   D   | 110
------------------------
 2 |  202 |       |
------------------------
   |      |   A   | 200
   |      |   B   | 350
   |      |   C   | 100
   |      |   D   | 110

I've tried with code - docss(row['code']) - docss.code and many more.

Hope someone helps me. Thankyou!

Avatar
Discard

Hi, pass a dictionary from your parser to get data in the required format or give a t-if condition for new lines.

Author

Hi, i've solved the problem with t-if. Thanks!

Author Best Answer

I've solved the problem:

<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
<td class="pb_text_center line_left">                                   
    <t t-set="num" t-value="num + 1"/>
    <t t-esc="num"/>
</td>
<td class="pb_text_left line_left">
    <span t-esc="row['code']"/>
</td>

<tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
  <t t-if="row['code']==row_detail['code']">
    <td class="pb_text_center line_left">
    </td>
    <td class="pb_text_left line_left">
    </td>
    <td class="pb_text_left line_left">
        <span t-esc="row_detail['brand']"/>
    </td>
    <td class="pb_text_left line_left">
        <span t-esc="row_detail['cost']"/>
    </td>
  </t>
</tr>
Avatar
Discard