<odoo>

    <template id="report_payment_receipt_document_cfdi">
        <t t-call="web.external_layout">
            <t t-set="o" t-value="o.with_context(lang=lang)" />
            <t t-set="cfdi" t-value="o.cfdi_document_id" t-if="o.cfdi_document_id" />
            <div class="page" style="font-size: 12px;">
                <h3>Comprobante de Pago
                    <span t-field="o.name" t-if="not cfdi" />
                    <span t-field="cfdi.name" t-if="cfdi" />
                </h3>
                <div id="informations" class="row mt-2 mb-4 mx-1">
                    <div
                        class="col-auto col-3 mw-100 m-0 p-0"
                        t-if="o.date"
                        name="invoice_date"
                    >
                        <t t-if="o.move_type == 'out_invoice'">
                            <strong>Fecha de Factura:</strong>
                        </t>
                        <t t-elif="o.move_type == 'out_refund'">
                            <strong>Fecha de Nota de Crédito:</strong>
                        </t>
                        <t t-elif="o.move_type == 'out_receipt'">
                            <strong>Fecha de Recibo:</strong>
                        </t>
                        <t t-else="">
                            <strong>Fecha:</strong>
                        </t>
                        <p class="m-0" t-field="o.date" />
                    </div>

                    <div t-if="o.invoice_payment_term_id" class="col-auto col-3 mw-100">
                        <strong>Plazo de Pago:</strong>
                        <p name="payment_term">
                            <span t-field="o.invoice_payment_term_id.name" />
                        </p>
                    </div>
                    <div
                        class="col-auto col-2 mw-100 p-0"
                        t-if="o.payment_form_id"
                        name="cfdi_payment_form"
                    >
                        <strong>Forma de Pago:</strong>
                        <p class="m-0" t-field="o.payment_form_id" />
                    </div>
                </div>

                <table class="table table-sm" t-if="cfdi">
                    <thead>
                        <th>Folio</th>
                        <th>UUID</th>
                        <th>Parcialidad</th>
                        <th>Saldo Anterior</th>
                        <th>Importe Pagado</th>
                        <th>Saldo Insoluto</th>
                        <th>Impuestos</th>
                    </thead>
                    <tbody>
                        <t
                            t-foreach="o.prepare_payment_cfdi()['RelatedDocuments']"
                            t-as="payment_line"
                        >
                            <tr>
                                <td>
                                    <span t-out="payment_line['Folio']" />
                                </td>
                                <td>
                                    <span t-out="payment_line['Uuid']" />
                                </td>
                                <td>
                                    <span
                                        t-out="payment_line['PartialityNumber'] - 1"
                                    />
                                </td>
                                <td>
                                    <span
                                        t-out="payment_line['PreviousBalanceAmount']"
                                    />
                                </td>
                                <td>
                                    <span t-out="payment_line['AmountPaid']" />
                                </td>
                                <td>
                                    <span
                                        t-out="payment_line['PreviousBalanceAmount'] - payment_line['AmountPaid']"
                                    />
                                </td>
                                <td>
                                    <t t-if="'Taxes' in payment_line">
                                        <t t-foreach="payment_line['Taxes']" t-as="tax">
                                            <span t-out="tax['Total']" />
                                            <br />
                                            <span
                                                t-out="tax['Name'] + ' ' + str(tax['Rate'] * 100) + '% '"
                                            />
                                        </t>
                                    </t>
                                </td>
                            </tr>
                        </t>
                    </tbody>
                </table>

                <t t-call="l10n_mx_cfdi.cfdi_payment_data" t-if="cfdi" />
                <t t-call="l10n_mx_cfdi.cfdi_signature_data" t-if="cfdi" />
            </div>
        </t>
    </template>

    <template
        id="report_payment_receipt"
        inherit_id="account.report_payment_receipt"
        priority="99"
    >
        <t
            t-call="account.report_payment_receipt_document"
            t-lang="lang"
            position="replace"
        >
            <t
                t-call="l10n_mx_cfdi.report_payment_receipt_document_cfdi"
                t-lang="lang"
                t-if="o.cfdi_document_id"
            />
            <t
                t-call="account.report_payment_receipt_document"
                t-lang="lang"
                t-else=""
            />
        </t>
    </template>

</odoo>
