<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <template id="report_journal_entry_document">
        <t t-call="web.external_layout">
            <t t-set="o" t-value="o.with_context(lang=lang)"/>
            <div class="page">
                <h2>
                    <span t-field="o.name"/>
                </h2>
                <div id="informations" class="row mb-4">
                    <div class="col" t-if="o.date" name="date">
                        <strong>Accounting Date:</strong>
                        <div t-field="o.date"/>
                    </div>
                    <div class="col" t-if="o.ref"
                         name="ref">
                        <strong>Reference:</strong>
                        <div t-field="o.ref"/>
                    </div>
                    <div class="col" groups="base.group_multi_company" name="company">
                        <strong>Company :</strong>
                        <div t-field="o.company_id.name"/>
                    </div>
                    <div class="col" t-if="o.journal_id" name="journal">
                        <strong>Journal</strong>
                        <div t-field="o.journal_id.name"/>
                    </div>
                    <div class="col" t-if="o.partner_id" name="customer">
                        <strong>Partner</strong>
                        <div t-field="o.partner_id.name"/>
                    </div>
                </div>
                <t t-set="total_debit" t-value="0.0"/>
                <t t-set="total_credit" t-value="0.0"/>
                <div class="clearfix invoice_main">
                    <div class="page mb-4">
                        <table class="table o_main_table table-borderless avoid-page-break-inside" name="lines_content">
                            <thead>
                                <tr>
                                    <th name="th_account" class="text-left">Account</th>
                                    <th name="th_partner" class="text-left">Partner</th>
                                    <th name="th_label" class="text-left">Label</th>
                                    <th
                                        name="th_amount_currency"
                                        class="text-left"
                                        groups="base.group_multi_currency"
                                    >Amount in Currency
                                    </th>
                                    <th name="th_debit" class="text-left">Debit</th>
                                    <th name="th_credit" class="text-left">Credit</th>
                                    <th
                                        name="th_tax_id"
                                        class="text-left"
                                    >Originator Tax
                                    </th>
                                    <th name="th_tax_ids" class="text-left">Taxes</th>
                                </tr>
                            </thead>
                            <tbody>
                                <t t-foreach="o.line_ids" t-as="line">
                                    <t
                                        t-set="total_debit"
                                        t-value="total_debit + line.debit"
                                    />
                                    <t
                                        t-set="total_credit"
                                        t-value="total_credit + line.credit"
                                    />
                                    <tr>
                                        <td name='tb_account'>
                                            <span t-field="line.account_id.display_name"/>
                                        </td>
                                        <td name='tb_partner'>
                                            <span t-field="line.partner_id.name"/>
                                        </td>
                                        <td name='tb_line_name'>
                                            <span t-field="line.name"/>
                                        </td>
                                        <td
                                            name='tb_amount_currency'
                                            groups="base.group_multi_currency"
                                        >
                                            <t t-if="line.currency_id">
                                                <span
                                                    t-esc="line.amount_currency"
                                                    t-options='{"widget": "monetary", "display_currency": line.currency_id}'
                                                />
                                            </t>
                                        </td>
                                        <td name='tb_debit'>
                                            <span
                                                t-esc="line.debit"
                                                t-options='{"widget": "monetary", "display_currency": line.company_currency_id}'
                                            />
                                        </td>
                                        <td name='tb_credit'>
                                            <span
                                                t-esc="line.credit"
                                                t-options='{"widget": "monetary", "display_currency": line.company_currency_id}'
                                            />
                                        </td>
                                        <td name='tb_originator_tax'>
                                            <span
                                                class="text-nowrap"
                                                t-esc="line.tax_line_id.name"
                                            />
                                        </td>
                                        <td
                                            t-attf-class="text-left {{ 'd-none d-md-table-cell' if report_type == 'html' else '' }}"
                                        >
                                            <span
                                                t-raw="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))"
                                                id="line_tax_ids"/>
                                        </td>
                                    </tr>
                                </t>
                                <tr class="o_subtotal" style="border-top: 1px solid #000;">
                                    <td name='tf_account'/>
                                    <td name='tf_partner'/>
                                    <td name='tf_line_name'/>
                                    <td
                                        name='tf_analytic'
                                        groups="analytic.group_analytic_accounting"
                                    />
                                    <td
                                        name='tf_amount_currency'
                                        groups="base.group_multi_currency"
                                    />
                                    <td name='tf_debit'>
                                        <span
                                            t-esc="total_debit"
                                            t-options='{"widget": "monetary", "display_currency": o.company_currency_id}'
                                        />
                                    </td>
                                    <td name='tf_credit'>
                                        <span
                                            t-esc="total_credit"
                                            t-options='{"widget": "monetary", "display_currency": o.company_currency_id}'
                                        />
                                    </td>
                                    <td name='tf_originator_tax'/>
                                    <td name='tb_taxes'/>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </t>
    </template>

    <template id="report_journal_entries">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="o">
                <t
                    t-call="account_move_print.report_journal_entry_document"
                    t-lang="o.user_id.lang"
                />
            </t>
        </t>
    </template>

    <record id="action_report_journal_entries" model="ir.actions.report">
        <field name="name">Journal Entries</field>
        <field name="model">account.move</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">account_move_print.report_journal_entries</field>
        <field name="report_file">account_move_print.report_journal_entries</field>
        <field name="binding_model_id" ref="account.model_account_move"/>
        <field name="binding_view_types">list,form</field>
    </record>
</odoo>
