<?xml version="1.0"?>
<t t-name="l10n_es_edi_facturae.invoice_type">
            <Invoice>
                <InvoiceHeader>
                    <InvoiceNumber t-out="invoice['invoice_record'].name"/>
                    <InvoiceDocumentType t-out="invoice['InvoiceDocumentType']"/>
                    <InvoiceClass t-out="invoice['InvoiceClass']"/>
                    <t t-if="refund_multiplier == -1" t-call="l10n_es_edi_facturae.corrective_type"/>
                </InvoiceHeader>
                <InvoiceIssueData>
                    <IssueDate t-out="invoice['invoice_record'].invoice_date.isoformat()"/>
                    <OperationDate t-out="invoice['InvoiceIssueData'].get('OperationDate')"/>
                    <InvoicingPeriod t-if="invoice['InvoiceIssueData'].get('InvoicingPeriod')">
                        <StartDate t-out="invoice['InvoiceIssueData']['InvoicingPeriod']['StartDate']"/>
                        <EndDate t-out="invoice['InvoiceIssueData']['InvoicingPeriod']['EndDate']"/>
                    </InvoicingPeriod>
                    <InvoiceCurrencyCode t-out="invoice['invoice_currency'].name"/>
                    <ExchangeRateDetails t-if="invoice['InvoiceIssueData'].get('ExchangeRateDetails')">
                        <ExchangeRate t-out="invoice['InvoiceIssueData']['ExchangeRate']"/>
                        <ExchangeRateDate t-out="(invoice['invoice_record'].invoice_date or invoice['invoice_record'].date).isoformat()"/>
                    </ExchangeRateDetails>
                    <TaxCurrencyCode t-out="invoice['invoice_currency'].name"/>
                    <LanguageName t-out="invoice['InvoiceIssueData']['LanguageName']"/>
                    <ReceiverTransactionReference t-out="invoice['InvoiceIssueData']['ReceiverTransactionReference']"/>
                    <FileReference t-out="invoice['InvoiceIssueData']['FileReference']"/>
                    <ReceiverContractReference t-out="invoice['InvoiceIssueData']['ReceiverContractReference']"/>
                </InvoiceIssueData>
                <TaxesOutputs>
                    <t t-foreach="invoice['TaxOutputs']" t-as="tax"><t t-call="l10n_es_edi_facturae.tax_type"/></t>
                </TaxesOutputs>
                <TaxesWithheld t-if="invoice.get('TaxesWithheld')">
                    <t t-foreach="invoice['TaxesWithheld']" t-as="tax"><t t-call="l10n_es_edi_facturae.tax_type"/></t>
                </TaxesWithheld>
                <InvoiceTotals>
                    <TotalGrossAmount t-out="float_repr(refund_multiplier*invoice['TotalGrossAmount'], file_currency.decimal_places)"/>
                    <GeneralDiscounts t-if="invoice.get('GeneralDiscounts')">
                        <t t-foreach="invoice['GeneralDiscounts']" t-as="discount">
                            <Discount>
                                <DiscountReason t-out="discount['DiscountReason']"/>
                                <DiscountRate t-out="discount.get('DiscountRate')"/>
                                <DiscountAmount t-out="float_repr(refund_multiplier*discount['DiscountAmount'], file_currency.decimal_places)"/>
                            </Discount>
                        </t>
                    </GeneralDiscounts>
                    <GeneralSurcharges t-if="invoice.get('GeneralSurcharges')">
                        <t t-foreach="invoice['GeneralSurcharges']" t-as="charge">
                            <Charge>
                                <ChargeReason t-out="charge['ChargeReason']"/>
                                <ChargeRate t-out="charge.get('ChargeRate')"/>
                                <ChargeAmount t-out="float_repr(refund_multiplier*charge['ChargeAmount'], file_currency.decimal_places)"/>
                            </Charge>
                        </t>
                    </GeneralSurcharges>
                    <TotalGeneralDiscounts t-if="invoice.get('TotalGeneralDiscounts')" t-out="float_repr(refund_multiplier*invoice['TotalGeneralDiscounts'], file_currency.decimal_places)"/>
                    <TotalGeneralSurcharges t-if="invoice.get('TotalGeneralSurcharges')" t-out="float_repr(refund_multiplier*invoice['TotalGeneralSurcharges'], file_currency.decimal_places)"/>
                    <TotalGrossAmountBeforeTaxes t-out="float_repr(refund_multiplier*invoice['TotalGrossAmountBeforeTaxes'], file_currency.decimal_places)"/>
                    <TotalTaxOutputs t-out="float_repr(refund_multiplier*invoice['TotalTaxOutputs'], file_currency.decimal_places)"/>
                    <TotalTaxesWithheld t-out="float_repr(refund_multiplier*invoice['TotalTaxesWithheld'], file_currency.decimal_places)"/>
                    <InvoiceTotal t-out="float_repr(refund_multiplier*invoice['InvoiceTotal'], file_currency.decimal_places)"/>
                    <PaymentsOnAccount t-if="invoice.get('PaymentsOnAccount')">
                        <t t-foreach="invoice['PaymentsOnAccount']" t-as="payment">
                            <PaymentOnAccount>
                                <PaymentOnAccountDate t-out="payment['PaymentOnAccountDate']"/>
                                <PaymentOnAccountAmount t-out="float_repr(refund_multiplier*payment['PaymentOnAccountAmount'], file_currency.decimal_places)"/>
                            </PaymentOnAccount>
                        </t>
                    </PaymentsOnAccount>
                    <TotalFinancialExpenses t-if="invoice.get('ReimbursableExpensesAmount')" t-out="float_repr(refund_multiplier*invoice['ReimbursableExpensesAmount'], file_currency.decimal_places)"/>
                    <TotalOutstandingAmount t-out="float_repr(refund_multiplier*invoice['TotalOutstandingAmount'], file_currency.decimal_places)"/>
                    <TotalPaymentsOnAccount t-if="invoice.get('TotalPaymentsOnAccount')" t-out="float_repr(refund_multiplier*invoice['TotalPaymentsOnAccount'], file_currency.decimal_places)"/>
                    <AmountsWithheld t-if="invoice.get('AmountsWithheld')">
                        <WithholdingReason t-out="invoice['AmountsWithheld']['WithholdingReason']"/>
                        <WithholdingRate t-out="invoice['AmountsWithheld'].get('WithholdingRate')"/>
                        <WithholdingAmount t-out="float_repr(refund_multiplier*invoice['AmountsWithheld']['WithholdingAmount'], file_currency.decimal_places)"/>
                    </AmountsWithheld>
                    <TotalExecutableAmount t-out="float_repr(refund_multiplier*invoice['TotalExecutableAmount'], file_currency.decimal_places)"/>
                    <TotalReimbursableExpenses t-if="invoice.get('TotalReimbursableExpenses')" t-out="float_repr(refund_multiplier*invoice['TotalReimbursableExpenses'], file_currency.decimal_places)"/>
                </InvoiceTotals>
                <Items>
                    <t t-foreach="invoice['Items']" t-as="line"><t t-call="l10n_es_edi_facturae.invoice_line_type"/></t>
                </Items>
                <PaymentDetails t-if="invoice['PaymentDetails']">
                    <Installment t-foreach="invoice['PaymentDetails']" t-as="installment">
                        <InstallmentDueDate t-out="installment['InstallmentDueDate']"/>
                        <InstallmentAmount t-out="float_repr(installment['InstallmentAmount'], 2)"/>
                        <PaymentMeans t-out="installment['PaymentMeans']"/>
                        <AccountToBeCredited>
                            <IBAN t-out="installment['AccountToBeCredited']['IBAN']"/>
                            <BIC t-out="installment['AccountToBeCredited']['BIC']"/>
                        </AccountToBeCredited>
                    </Installment>
                </PaymentDetails>
                <LegalLiterals t-if="invoice.get('LegalLiterals')">
                    <t t-foreach="invoice['LegalLiterals']" t-as="reference"><LegalReference t-out="reference[:250]"/></t>
                </LegalLiterals>
            </Invoice>
        </t>

        