{% from "template_facturae_macros.xml" import administrative_center, address, contact %} 3.2 I {# The invoice is signed by Issuer (the company, only supported out invoices) #} EM {# As InvoiceIssuerType != TE, ThirdParty element is not generated #} {{ ('%s%s' % (invoice.company.party.vat_code, invoice.number))[:70] }} 1 {{ invoice.total_amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} {# TODO: it must to get amount_to_pay? #} {{ invoice.total_amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} {# TODO: it must to get amount_to_pay? #} {{ invoice.total_amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} EUR {# FactoryAssignmentData optional: not supported (factoring not supported) #} {{ invoice.company.party.facturae_person_type }} R {{ invoice.company.party.vat_code[:30] }} {# Optional. It could be the ID or the code #} {{ invoice.company.party.id_electronet }} {% if invoice.company.party.oficina_contable and invoice.company.party.addresses %}{{ administrative_center(invoice.company.party.oficina_contable.rstrip(), '01', invoice.company.party) }}{% endif %} {% if invoice.company.party.organo_gestor and invoice.company.party.addresses %}{{ administrative_center(invoice.company.party.organo_gestor.rstrip(), '02', invoice.company.party) }}{% endif %} {% if invoice.company.party.unidad_tramitadora and invoice.company.party.addresses %}{{ administrative_center(invoice.company.party.unidad_tramitadora.rstrip(), '03', invoice.company.party) }}{% endif %} {% if invoice.company.party.organo_proponente and invoice.company.party.addresses %}{{ administrative_center(invoice.company.party.organo_proponente.replace('\n', '').rstrip(), '04', invoice.company.party) }}{% endif %} {{ invoice.company.party.name[:80] }} {{ address(invoice.company.party.addresses[0]) }} {% if invoice.company.party.contact_mechanisms %} {{ contact(invoice.company.party) }} {% endif %} {{ invoice.party.facturae_person_type }} R {{ invoice.party.vat_code[:30] }} {# Optional. It could be the ID or the code #} {{ invoice.party.id_electronet }} {% if invoice.party.oficina_contable %}{{ administrative_center(invoice.party.oficina_contable, '01', invoice.party) }}{% endif %} {% if invoice.party.organo_gestor %}{{ administrative_center(invoice.party.organo_gestor, '02', invoice.party) }}{% endif %} {% if invoice.party.unidad_tramitadora %}{{ administrative_center(invoice.party.unidad_tramitadora, '03', invoice.party) }}{% endif %} {% if invoice.party.organo_proponente %}{{ administrative_center(invoice.party.organo_proponente, '04', invoice.party) }}{% endif %} {{ invoice.party.name and invoice.party.name[:80] or invoice.party.code[:80] }} {% if invoice.party.trade_name %} {{ invoice.party.trade_name[:40] }} {% endif %} {# RegistrationData optional: not supported #} {{ address(invoice.invoice_address) }} {% if invoice.party.contact_mechanisms %} {{ contact(invoice.party) }} {% endif %} {{ invoice.number[:20] }} {# InvoiceSeriesCode optional: not supported #} {# TODO: FA (Factura Simplificada) not supported #} FC {# TODO: Types not supported: - OC (O. Recapitulativa) - CO (Duplicado Original) - CR, (D. Rectificativa) - CC (D. Recapitulativa) #} {{ 'OO' if not invoice.credited_invoices else 'OR' }} {% if invoice.credited_invoices %} {{ invoice.credited_invoices and invoice.credited_invoices[0].number[:20] }} {# InvoiceSeriesCode Optional: not supported #} {{ invoice.rectificative_reason_code }} {{ invoice.rectificative_reason_spanish_description }} {# TODO: Methods not supported: - 02 (solo se anotan los detalles ya rectificados) - 03 (Rectificación por descuento por volumen de operaciones durante un periodo) - 04 (Autorizadas por la Agencia Tributaria) #} 01 Rectificación Íntegra {# AdditionalReasonDescription optional: not supported #} {% endif %} {{ invoice.invoice_date.isoformat() }} {# OperationDate required only if is different to IssueDate, but we consider OperatinDate==invoice_date: not supported #} {# PlaceOfIssue optional: not supported #} {# InvoicingPeriod required only for Recapitulativas or temporary service: not supported #} EUR EUR es {% for invoice_tax in invoice.taxes_outputs %} {{ invoice_tax.tax.report_type }} {{ invoice_tax.tax.rate * 100 }} {{ invoice_tax.base }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.base, euro) }} {% endif %} {{ invoice_tax.amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% endif %} {# TODO: special taxes not supported - SpecialTaxableBase - SpecialTaxAmount #} {% if invoice_tax.tax.recargo_equivalencia %} {# TODO: EquivalenceSurchace must to have its own Tax entry or it must to go to the IVA line? TaxRate == EquivalenceSurcharge and TaxAmount == EquivalenceSurchargeAmount? #} {{ (invoice_tax.tax.rate * 100).quantize(Decimal('0.01')) }} {{ invoice_tax.amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% endif %} {% endif %} {% endfor %} {% if invoice.taxes_withheld %} {% for invoice_tax in invoice.taxes_withheld %} {{ invoice_tax.tax.report_type }} {{ invoice_tax.tax.rate * 100 }} {{ invoice_tax.base }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.base, euro) }} {% endif %} {{ invoice_tax.amount }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% endif %} {% endfor %} {% endif %} {{ invoice.untaxed_amount }} {# TODO: GeneralDiscounts and TotalGeneralDiscounts (account_invoice_discount_global) not supported #} {# TODO: GeneralSurcharges and TotalGeneralSurcharges not supported #} {{ invoice.untaxed_amount }} {{ invoice.taxes_outputs | sum(attribute='amount', start=Decimal('0.00')) }} {{ invoice.taxes_withheld | sum(attribute='amount', start=Decimal('0.00')) }} {{ invoice.total_amount }} {# TODO: optional, not supported - Subsidies - PaymentsOnAccount, TotalPaymentsOnAccount - ReimbursableExpenses, TotalReimbursableExpenses (suplidos?) - TotalFinancialExpenses (account_payment_type_cost?) - AmountsWithheld #} {{ invoice.total_amount }} {{ invoice.total_amount }} {% for line in invoice.lines if line.type == 'line' %} {# TODO: optional, not supported - Issuer/ReceiverContractReference, Issuer/ReceiverContractDate (contract) - Issuer/ReceiverTransactionReference, Issuer/ReceiverTransactionDate (sale, contract...) - FileReference, FileDate - SequenceNumber - DeliveryNotesReferences (account_invoice_stock) - LineItemPeriod - TransactionDate - Extensions #} {{ line.description and line.description[:2500] or '' }} {{ line.quantity }} {{ UOM_CODE2TYPE.get(line.unit.symbol, '05') if line.unit else '05' }} {{ '%0.6f'|format(line.unit_price) }} {{ '%0.6f'|format(line.amount) }} {# TODO: optional, not supported - DiscountsAndRebates (account_invoice_discount) - Charges #} {{ '%0.6f'|format(line.amount) }} {% if line.taxes_withheld %} {% for line_tax in invoice.taxes_withheld %} {{ line_tax.tax.report_type }} {{ line_tax.tax.rate * 100 }} {{ '%0.2f'|format(line.amount) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% endif %} {{ '%0.2f'|format(line.amount * line_tax.tax.rate) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% endif %} {% endfor %} {% endif %} {% for line_tax in line.taxes_outputs %} {{ line_tax.tax.report_type }} {{ line_tax.tax.rate * 100 }} {{ '%0.2f'|format(line.amount) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% endif %} {{ '%0.2f'|format(line.amount * line_tax.tax.rate) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% endif %} {# TODO: special taxes not supported - SpecialTaxableBase - SpecialTaxAmount #} {% if line_tax.tax.recargo_equivalencia %} {# TODO: EquivalenceSurchace must to have its own Tax entry or it must to go to the IVA line? TaxRate == EquivalenceSurcharge and TaxAmount == EquivalenceSurchargeAmount? #} {{ (line_tax.tax.rate * 100).quantize(Decimal('0.01')) }} {{ '%0.2f'|format(line.amount * line_tax.tax.rate) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% endif %} {% endif %} {% endfor %} {% if line.taxes_additional_line_item_information %} {% for key, description in line.taxes_additional_line_item_information.items() %} {{ key }} = {{ description }} {% endfor %} {% endif %} {# TODO: SpecialTaxableEvent not supported #} {% if line.product and line.product.code %} {{ line.product.code }} {% endif %} {% endfor %} {% if invoice.payment_details %} {% for move_line in invoice.payment_details %} {{ move_line.maturity_date.isoformat() }} {{ ((move_line.debit - move_line.credit) | abs).quantize(Decimal('0.01')) }} {{ move_line.payment_type.facturae_type }} {% if move_line.payment_type.facturae_type == '04' %} {% for number in (move_line.bank_account.numbers|selectattr('type', 'equalto', 'iban')) %}{% if loop.first %}{{ number.number_compact }}{% endif %}{% endfor %} {# Unnecessary if IBAN is supplied: AccountNumber, BankCode, BranchCode, BranchInSpainAddress, OverseasBranchAddress, BIC #} {% elif move_line.payment_type.facturae_type == '02' %} {% for number in (move_line.bank_account.numbers|selectattr('type', 'equalto', 'iban')) %}{% if loop.first %}{{ number.number_compact }}{% endif %}{% endfor %} {# Unnecessary if IBAN is supplied: AccountNumber, BankCode, BranchCode, BranchInSpainAddress, OverseasBranchAddress, BIC #} {# optional, not supported: - PaymentReconciliationReference - CollectionAdditionalInformation - RegulatoryReportingData (for international operations) - DebitReconciliationReference #} {% endif %} {% endfor %} {% endif %} {% for inv_tax in invoice.taxes %} {% if inv_tax.tax and inv_tax.tax.report_description %} {{ inv_tax.tax.report_description[:250] }} {% endif %} {% endfor %} {# Extensions optional, not supported #}