{% from "template_facturae_macros.xml" import administrative_center, address, contact, registration_data %} 3.2.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.tax_identifier.code, invoice.number))[:70] }} 1 {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} {# TODO: it must to get amount_to_pay? #} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} {# TODO: it must to get amount_to_pay? #} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice.total_amount, euro) }} {% endif %} {{ invoice.currency.code.upper() }} {# FactoryAssignmentData optional: not supported (factoring not supported) #} {{ invoice.company.party.facturae_person_type }} {{ invoice.company.party.facturae_residence_type }} {{ invoice.company.party.tax_identifier.code[:30] }} {# Optional. It could be the ID or the code #} {% if invoice.company.party.code and invoice.company.party.code | length < 10 %} {{ invoice.company.party.code|int or invoice.company.party.id }} {% endif %} {% if invoice.company.party.oficina_contable or invoice.company.party.organo_gestor or invoice.company.party.unidad_tramitadora or invoice.company.party.organo_proponente %} {% if invoice.company.party.oficina_contable %}{{ administrative_center(invoice.company.party.oficina_contable, '01', invoice.company.party) }}{% endif %} {% if invoice.company.party.organo_gestor %}{{ administrative_center(invoice.company.party.organo_gestor, '02', invoice.company.party) }}{% endif %} {% if invoice.company.party.unidad_tramitadora %}{{ administrative_center(invoice.company.party.unidad_tramitadora, '03', invoice.company.party) }}{% endif %} {% if invoice.company.party.organo_proponente %}{{ administrative_center(invoice.company.party.organo_proponente, '04', invoice.company.party) }}{% endif %} {% endif %} {{ invoice.company.party.name[:80] }} {% if invoice.company.party.trade_name %} {{ invoice.company.party.trade_name[:40] }} {% endif %} {% if invoice.company %} {{ registration_data(invoice.company) }} {% endif %} {% if invoice.company.party.addresses %} {{ address(invoice.company.party.addresses[0]) }} {% endif %} {% if invoice.company.party.contact_mechanisms %} {{ contact(invoice.company.party) }} {% endif %} {{ invoice.party.facturae_person_type }} {{ invoice.party.facturae_residence_type }} {{ invoice.party.tax_identifier.code[:30] }} {# Optional. It could be the ID or the code #} {% if invoice.party.code and invoice.party.code | length < 10 %} {{ invoice.party.code|int or invoice.party.id }} {% endif %} {% if invoice.party.oficina_contable or invoice.party.organo_gestor or invoice.party.unidad_tramitadora or invoice.party.organo_proponente %} {% 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 %} {% endif %} {% if invoice.party.facturae_person_type == 'J' %} {{ invoice.party.name and invoice.party.name[:80] or invoice.party.code[:80] }} {% if invoice.party.trade_name %} {{ invoice.party.trade_name[:40] }} {% endif %} {{ address(invoice.invoice_address) }} {% if invoice.party.contact_mechanisms %} {{ contact(invoice.party) }} {% endif %} {% else %} {{ invoice.party.name and invoice.party.name.split(' ', 2)[0][:40] or invoice.party.code[:40] }} {{ invoice.party.name and invoice.party.name.split(' ', 2)[1][:40] }} {% if invoice.party.name.split(' ') | length > 2 %} {{ invoice.party.name and invoice.party.name.split(' ', 2)[2][:40] }} {% endif %} {{ address(invoice.invoice_address) }} {% if invoice.party.contact_mechanisms %} {{ contact(invoice.party) }} {% endif %} {% 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: it is the period or the term (VAT report period?) #} {{ invoice.credited_invoices[0].move.period.start_date.isoformat() }} {{ invoice.credited_invoices[0].move.period.end_date.isoformat() }} {# 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 #} {# TODO: InvoiceIssueDate: Nuevo campo para definir la fecha de expedición de la factura rectificada. Valor obligatorio en el supuesto de que la etiqueta CorrectionMethod tome los valores “01” o “02” #} {% 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 #} {{ invoice.currency.code.upper() }} {% if invoice.currency != euro %} {{ Invoice.double_up_to_eight(exchange_rate) }} {{ exchange_rate_date }} {% endif %} EUR {{ invoice.party_lang[:2] if invoice.party_lang else 'es' }} {{ invoice.reference and invoice.reference[:20] or '' }} {% for invoice_tax in invoice.taxes_outputs %} {{ invoice_tax.tax.report_type }} {{ Invoice.double_up_to_eight(invoice_tax.tax.rate * 100) }} {{ Invoice.double_up_to_eight(invoice_tax.base) }} {% if invoice.currency != euro %} {{ Invoice.double_up_to_eight(invoice_tax.base) }} {% endif %} {{ Invoice.double_up_to_eight(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')) }} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% 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.double_up_to_eight(invoice_tax.tax.rate * 100) }} {{ Currency.compute(invoice.currency, invoice_tax.base, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.base, euro) }} {% endif %} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, invoice_tax.amount, euro) }} {% endif %} {% endfor %} {% endif %} {{ Invoice.double_up_to_eight(invoice.untaxed_amount) }} {# TODO: GeneralDiscounts and TotalGeneralDiscounts (account_invoice_discount_global) not supported #} {# TODO: GeneralSurcharges and TotalGeneralSurcharges not supported #} {{ Invoice.double_up_to_eight(invoice.untaxed_amount) }} {{ Invoice.double_up_to_eight(invoice.taxes_outputs | sum(attribute='amount', start=Decimal(0))) }} {{ Invoice.double_up_to_eight(invoice.taxes_withheld | sum(attribute='amount', start=Decimal(0))) }} {{ Invoice.double_up_to_eight(invoice.total_amount) }} {# TODO: optional, not supported - Subsidies - PaymentsOnAccount, TotalPaymentsOnAccount - ReimbursableExpenses, TotalReimbursableExpenses (suplidos?) - TotalFinancialExpenses (account_payment_type_cost?) - AmountsWithheld #} {{ Invoice.double_up_to_eight(invoice.total_amount) }} {{ Invoice.double_up_to_eight(invoice.total_amount) }} {% for line in invoice.lines if line.type == 'line' %} {# TODO: optional, not supported - Issuer/ReceiverContractReference, Issuer/ReceiverContractDate (contract) - FileReference, FileDate - SequenceNumber - DeliveryNotesReferences (account_invoice_stock) - TransactionDate - Extensions #} {{ line.facturae_receiver_transaction_reference }} {{ line.facturae_item_description }} {{ line.quantity }} {{ UOM_CODE2TYPE.get(line.unit.symbol, '05') if line.unit else '05' }} {{ Invoice.double_up_to_eight(line.unit_price) }} {{ Invoice.double_up_to_eight(line.amount) }} {# TODO: optional, not supported - DiscountsAndRebates (account_invoice_discount) - Charges #} {{ Invoice.double_up_to_eight(line.amount) }} {% if line.taxes_withheld %} {% for line_tax in invoice.taxes_withheld %} {{ line_tax.tax.report_type }} {{ Invoice.double_up_to_eight(line_tax.tax.rate * 100) }} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% endif %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% 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 }} {{ Currency.compute(invoice.currency, line_tax.tax.rate * 100, euro) }} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount, euro) }} {% endif %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% 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')) }} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% if invoice.currency != euro %} {{ Currency.compute(invoice.currency, line.amount * line_tax.tax.rate, euro) }} {% endif %} {% endif %} {% endfor %} {% if line.origin and line.origin.contract %} {{ line.origin.start_date }} {{ line.origin.end_date }} {% endif %} {% if line.taxes_additional_line_item_information or line.note %} {% if line.taxes_additional_line_item_information %} {% for key, description in line.taxes_additional_line_item_information.items() %} {{ key }} = {{ description }} {% endfor %} {% elif line.note %} {{ line.note }} {% endif %} {% endif %} {# TODO: SpecialTaxableEvent not supported #} {% if line.product and line.product.code %} {{ line.facturae_article_code[:20] }} {% endif %} {% endfor %} {% if invoice.payment_details %} {% for move_line in invoice.payment_details %} {{ move_line.maturity_date.isoformat() }} {{ Currency.compute(invoice.currency, ((move_line.debit - move_line.credit) | abs).quantize(Decimal('0.01')), euro) }} {{ 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[:60] - CollectionAdditionalInformation[:2500] - RegulatoryReportingData (for international operations) - DebitReconciliationReference[:60] #} {% 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 %} {# optional, not supported: - RelatedInvoice[:40] - RelatedDocuments - Extensions #} # [:2500] Factura generada con Tryton (https://www.tryton.org) {# Extensions optional, not supported #}