Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
655 Lượt xem

In this code, the section is printed after the line items. As shown in the image I shared, it should appear the related line items. Please help me fix it


<tbody class="invoice_tbody" style="border-bottom:2px solid gainsboro;">
<t t-set="current_subtotal" t-value="0"/>
<t t-set="current_subtotal_TTC" t-value="0"/>
<t t-foreach="o.invoice_line_ids" t-as="line">
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>
<t t-set="current_subtotal_TTC" t-value="current_subtotal_TTC + line.price_total"/>
<tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
<t t-if="line.display_type == 'product'" name="account_invoice_line_accountable">
<td name="account_invoice_line_name">
<span t-field="line.name"/>
</td>
<!-- <td class="d-none">-->
<!-- <span t-field="line.origin"/>-->
<!-- </td>-->
<td class="text-end">
<span t-field="line.quantity"/>
<span t-field="line.product_uom_id" groups="uom.group_uom"/>
</td>
<td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.price_unit"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
<td t-if="display_discount"
t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.discount"/>
</td>
<td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))"/>
</td>
<td style="border-top-style: hidden;" class="text-end o_price_total">
<span t-field="line.price_subtotal"/>
</td>
<td style="border-top-style: hidden;" class="text-end o_price_total">
<span t-field="line.price_total"/>
</td>
</t>
<t t-if="line.display_type == 'line_section'">
<td t-att-colspan="colspan" style="font-weight:bold;">
<span t-field="line.name"/>
</td>
<t t-set="current_section" t-value="line"/>
<t t-set="current_subtotal" t-value="0"/>
<t t-set="current_subtotal_TTC" t-value="0"/>
</t>
<t t-if="line.display_type == 'line_note'"
style="font-size:11.5px !important;font-weight:bold;">
<td t-att-colspan="colspan" style="font-weight:bold; white-space: pre-wrap;">
<span t-esc="line.name"/>
</td>
</t>
</tr>
<t t-if="current_section and (line_last or o.invoice_line_ids[line_index+1].display_type == 'line_section')">
<tr class="is-subtotal text-end">
<td></td>
<td></td>
<td></td>

<td>
<strong class="mr16">Sous-total</strong>

</td>
<td>
<span
t-esc="current_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
<td>
<span
t-esc="current_subtotal_TTC"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
</tr>
</t>
</t>
</tbody>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You need to move the section and note line checks (line.display_type == 'line_section' and line.display_type == 'line_note') above the product line rendering block.


Please refer to the code below:


<tbody class="invoice_tbody" style="border-bottom:2px solid gainsboro;">
<t t-set="current_subtotal" t-value="0"/>
<t t-set="current_subtotal_TTC" t-value="0"/>
<t t-foreach="o.invoice_line_ids" t-as="line">
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>
<t t-set="current_subtotal_TTC" t-value="current_subtotal_TTC + line.price_total"/>
<tr t-att-class="'bg-200 font-weight-bold o_line_section' if line.display_type == 'line_section' else 'font-italic o_line_note' if line.display_type == 'line_note' else ''">
<t t-if="line.display_type == 'line_section'">
<td t-att-colspan="colspan" style="font-weight:bold;">
<span t-field="line.name"/>
</td>
<t t-set="current_section" t-value="line"/>
<t t-set="current_subtotal" t-value="0"/>
<t t-set="current_subtotal_TTC" t-value="0"/>
</t>
<t t-if="line.display_type == 'line_note'"
style="font-size:11.5px !important;font-weight:bold;">
<td t-att-colspan="colspan" style="font-weight:bold; white-space: pre-wrap;">
<span t-esc="line.name"/>
</td>
</t>
<t t-if="line.display_type == 'product'" name="account_invoice_line_accountable">
<td name="account_invoice_line_name">
<span t-field="line.name"/>
</td>
<!-- <td class="d-none">-->
<!-- <span t-field="line.origin"/>-->
<!-- </td>-->
<td class="text-end">
<span t-field="line.quantity"/>
<span t-field="line.product_uom_id" groups="uom.group_uom"/>
</td>
<td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.price_unit"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
<td t-if="display_discount"
t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-field="line.discount"/>
</td>
<td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
<span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))"/>
</td>
<td style="border-top-style: hidden;" class="text-end o_price_total">
<span t-field="line.price_subtotal"/>
</td>
<td style="border-top-style: hidden;" class="text-end o_price_total">
<span t-field="line.price_total"/>
</td>
</t>
</tr>
<t t-if="current_section and (line_last or o.invoice_line_ids[line_index+1].display_type == 'line_section')">
<tr class="is-subtotal text-end">
<td></td>
<td></td>
<td></td>
<td>
<strong class="mr16">Sous-total</strong>
</td>
<td>
<span
t-esc="current_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
<td>
<span
t-esc="current_subtotal_TTC"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
</tr>
</t>
</t>
</tbody>


Hope it helps.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I have tried your code but still section is appeared at last, any ways thank you

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Maybe try to move the line.display_type == 'line_section' logic before the main <tr> is rendered so that the section row prints before the associated product lines. Like this:

<tbody class="invoice_tbody" style="border-bottom:2px solid gainsboro;">
    <t t-set="current_subtotal" t-value="0"/>
    <t t-set="current_subtotal_TTC" t-value="0"/>
    <t t-foreach="o.invoice_line_ids" t-as="line" t-index="line_index">
       
        <!-- SECTION HEADER FIRST -->
        <t t-if="line.display_type == 'line_section'">
            <tr class="bg-200 font-weight-bold o_line_section">
                <td t-att-colspan="colspan" style="font-weight:bold;">
                    <span t-field="line.name"/>
                </td>
            </tr>
            <t t-set="current_section" t-value="line"/>
            <t t-set="current_subtotal" t-value="0"/>
            <t t-set="current_subtotal_TTC" t-value="0"/>
        </t>

        <!-- NOTE LINE -->
        <t t-if="line.display_type == 'line_note'">
            <tr class="font-italic o_line_note">
                <td t-att-colspan="colspan" style="font-weight:bold; white-space: pre-wrap;">
                    <span t-esc="line.name"/>
                </td>
            </tr>
        </t>

        <!-- PRODUCT LINE -->
        <t t-if="line.display_type == 'product'" name="account_invoice_line_accountable">
            <tr>
                <td name="account_invoice_line_name">
                    <span t-field="line.name"/>
                </td>
                <td class="text-end">
                    <span t-field="line.quantity"/>
                    <span t-field="line.product_uom_id" groups="uom.group_uom"/>
                </td>
                <td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                    <span t-field="line.price_unit" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                </td>
                <td t-if="display_discount"
                    t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                    <span t-field="line.discount"/>
                </td>
                <td t-attf-class="text-end {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}">
                    <span t-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))"/>
                </td>
                <td class="text-end o_price_total" style="border-top-style: hidden;">
                    <span t-field="line.price_subtotal"/>
                </td>
                <td class="text-end o_price_total" style="border-top-style: hidden;">
                    <span t-field="line.price_total"/>
                </td>
            </tr>
            <!-- Update subtotals -->
            <t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>
            <t t-set="current_subtotal_TTC" t-value="current_subtotal_TTC + line.price_total"/>
        </t>

        <!-- SUBTOTAL AFTER LAST LINE IN SECTION -->
        <t t-if="current_section and (line_index + 1 == len(o.invoice_line_ids) or o.invoice_line_ids[line_index + 1].display_type == 'line_section')">
            <tr class="is-subtotal text-end">
                <td></td><td></td><td></td>
                <td><strong class="mr16">Sous-total</strong></td>
                <td>
                    <span t-esc="current_subtotal"
                          t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                </td>
                <td>
                    <span t-esc="current_subtotal_TTC"
                          t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
                </td>
            </tr>
        </t>

    </t>
</tbody>

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 25
3
0
thg 8 25
3
1
thg 8 25
216
0
thg 8 25
380
1
thg 8 25
420