<?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="information" class="row mt32 mb32">
                    <div class="col-auto mw-100 mb-2" name="date">
                        <strong>Accounting Date:</strong>
                        <p class="m-0" t-field="o.date" />
                    </div>
                    <div class="col-auto mw-100 mb-2" name="ref">
                        <strong>Reference:</strong>
                        <p class="m-0" t-field="o.ref" />
                    </div>
                    <div
                        class="col-auto mw-100 mb-2"
                        name="company"
                        groups="base.group_multi_company"
                    >
                        <strong>Company:</strong>
                        <p class="m-0" t-field="o.company_id.name" />
                    </div>
                    <div class="col-auto mw-100 mb-2" name="journal">
                        <strong>Journal:</strong>
                        <p class="m-0" t-field="o.journal_id.name" />
                    </div>
                    <div
                        class="col-auto mw-100 mb-2"
                        name="partner"
                        t-if="o.partner_id"
                    >
                        <strong>Partner:</strong>
                        <p class="m-0" 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="row">
                    <table name='lines_content' class="table table-sm o_main_table">
                        <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_analytic_account"
                                    class="text-left"
                                    groups="analytic.group_analytic_accounting"
                                >Analytic Account</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_analytic'
                                        groups="analytic.group_analytic_accounting"
                                    >
                                        <span t-field="line.analytic_account_id.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-esc="', '.join(map(lambda x: (x.description or x.name), line.tax_ids))"
                                            id="line_tax_ids"
                                        />
                                    </td>
                                </tr>
                            </t>
                        </tbody>
                        <tfooter>
                            <tr>
                                <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>
                        </tfooter>
                    </table>
                </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>
