Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 1 | {%- macro format_float(value) -%} |
| 2 | {{ "%.2f" % value|abs }} |
| 3 | {%- endmacro -%} |
| 4 | |
| 5 | {%- macro render_address(address) %} |
| 6 | <Indirizzo>{{ address.address_line1 }}</Indirizzo> |
| 7 | <CAP>{{ address.pincode }}</CAP> |
| 8 | <Comune>{{ address.city }}</Comune> |
Gaurav | 3f04613 | 2019-02-19 16:28:22 +0530 | [diff] [blame] | 9 | {%- if address.state_code %} |
| 10 | <Provincia>{{ address.state_code }}</Provincia> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 11 | {%- endif %} |
| 12 | <Nazione>{{ address.country_code|upper }}</Nazione> |
| 13 | {%- endmacro %} |
| 14 | |
| 15 | {%- macro render_discount_or_margin(item) -%} |
| 16 | {%- if item.discount_percentage > 0.0 or item.margin_type %} |
| 17 | <ScontoMaggiorazione> |
| 18 | {%- if item.discount_percentage > 0.0 %} |
| 19 | <Tipo>SC</Tipo> |
| 20 | <Percentuale>{{ format_float(item.discount_percentage) }}</Percentuale> |
| 21 | {%- endif %} |
| 22 | {%- if item.margin_rate_or_amount > 0.0 -%} |
| 23 | <Tipo>MG</Tipo> |
| 24 | {%- if item.margin_type == "Percentage" -%} |
| 25 | <Percentuale>{{ format_float(item.margin_rate_or_amount) }}</Percentuale> |
| 26 | {%- elif item.margin_type == "Amount" -%} |
| 27 | <Importo>{{ format_float(item.margin_rate_or_amount) }}</Importo> |
| 28 | {%- endif -%} |
| 29 | {%- endif %} |
| 30 | </ScontoMaggiorazione> |
| 31 | {%- endif -%} |
| 32 | {%- endmacro -%} |
| 33 | |
| 34 | <?xml version='1.0' encoding='UTF-8'?> |
Rohit Waghchaure | 0f98cb8 | 2019-02-26 15:01:30 +0530 | [diff] [blame] | 35 | <p:FatturaElettronica xmlns:ds="http://www.w3.org/2000/09/xmldsig#" |
| 36 | xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2" |
| 37 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 38 | versione="{{ doc.transmission_format_code }}" |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 39 | xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd"> |
| 40 | <FatturaElettronicaHeader> |
| 41 | <DatiTrasmissione> |
| 42 | <IdTrasmittente> |
| 43 | <IdPaese>{{ doc.company_address_data.country_code|upper or "IT" }}</IdPaese> |
| 44 | <IdCodice>{{ doc.company_fiscal_code or doc.company_tax_id | replace("IT","") }}</IdCodice> |
| 45 | </IdTrasmittente> |
| 46 | <ProgressivoInvio>{{ doc.progressive_number }}</ProgressivoInvio> |
| 47 | <FormatoTrasmissione>{{ doc.transmission_format_code }}</FormatoTrasmissione> |
| 48 | <CodiceDestinatario>{{ doc.customer_data.recipient_code }}</CodiceDestinatario> |
| 49 | {% if doc.company_data.phone or doc.company_data.email -%} |
| 50 | <ContattiTrasmittente> |
| 51 | {% if doc.company_data.phone -%}<Telefono>{{ doc.company_data.phone }}</Telefono>{%- endif %} |
| 52 | {% if doc.company_data.email -%}<Email>{{ doc.company_data.email }}</Email>{%- endif %} |
| 53 | </ContattiTrasmittente> |
| 54 | {% endif -%} |
| 55 | </DatiTrasmissione> |
| 56 | <CedentePrestatore> |
| 57 | <DatiAnagrafici> |
| 58 | <IdFiscaleIVA> |
| 59 | <IdPaese>{{ doc.company_address_data.country_code|upper or "IT"}}</IdPaese> |
| 60 | <IdCodice>{{ doc.company_tax_id | replace("IT","") }}</IdCodice> |
| 61 | </IdFiscaleIVA> |
| 62 | {%- if doc.company_fiscal_code %} |
| 63 | <CodiceFiscale>{{ doc.company_fiscal_code }}</CodiceFiscale> |
| 64 | {%- endif %} |
| 65 | <Anagrafica> |
| 66 | <Denominazione>{{ doc.company }}</Denominazione> |
| 67 | </Anagrafica> |
| 68 | <RegimeFiscale>{{ doc.company_fiscal_regime.split("-")[0] }}</RegimeFiscale> |
| 69 | </DatiAnagrafici> |
| 70 | <Sede> |
| 71 | {{ render_address(doc.company_address_data) }} |
| 72 | </Sede> |
| 73 | {%- if doc.company_data.registration_number %} |
| 74 | <IscrizioneREA> |
| 75 | <Ufficio>{{ doc.company_data.registrar_office_province }}</Ufficio> |
| 76 | <NumeroREA>{{ doc.company_data.registration_number }}</NumeroREA> |
| 77 | {%- if doc.company_data.share_capital_amount %} |
| 78 | <CapitaleSociale>{{ format_float(doc.company_data.share_capital_amount) }}</CapitaleSociale> |
| 79 | {%- endif %} |
| 80 | {%- if doc.company_data.no_of_members %} |
| 81 | <SocioUnico>{{ doc.company_data.no_of_members.split("-")[0] }}</SocioUnico> |
| 82 | {%- endif %} |
| 83 | {%- if doc.company_data.liquidation_state %} |
| 84 | <StatoLiquidazione>{{ doc.company_data.liquidation_state.split("-")[0] }}</StatoLiquidazione> |
| 85 | {%- endif %} |
| 86 | </IscrizioneREA> |
| 87 | {%- endif %} |
| 88 | </CedentePrestatore> |
| 89 | <CessionarioCommittente> |
| 90 | <DatiAnagrafici> |
| 91 | {%- if doc.customer_data.customer_type == "Individual" %} |
| 92 | <CodiceFiscale>{{ doc.customer_data.fiscal_code }}</CodiceFiscale> |
| 93 | <Anagrafica> |
| 94 | <Nome>{{ doc.customer_data.first_name }}</Nome> |
| 95 | <Cognome>{{ doc.customer_data.last_name }}</Cognome> |
| 96 | </Anagrafica> |
| 97 | {%- else %} |
| 98 | {%- if doc.customer_data.is_public_administration %} |
| 99 | <CodiceFiscale>{{ doc.customer_data.fiscal_code }}</CodiceFiscale> |
| 100 | {%- else %} |
| 101 | <IdFiscaleIVA> |
| 102 | <IdPaese>{{ doc.customer_address_data.country_code|upper or "IT" }}</IdPaese> |
| 103 | <IdCodice>{{ doc.tax_id | replace("IT","") }}</IdCodice> |
| 104 | </IdFiscaleIVA> |
| 105 | {%- endif %} |
| 106 | <Anagrafica> |
| 107 | <Denominazione>{{ doc.customer_name }}</Denominazione> |
| 108 | </Anagrafica> |
| 109 | {%- endif %} |
| 110 | </DatiAnagrafici> |
| 111 | {%- if doc.customer_address_data %} |
| 112 | <Sede> |
| 113 | {{ render_address(doc.customer_address_data) }} |
| 114 | </Sede> |
| 115 | {%- endif %} |
| 116 | </CessionarioCommittente> |
| 117 | </FatturaElettronicaHeader> |
| 118 | <FatturaElettronicaBody> |
| 119 | <DatiGenerali> |
| 120 | <DatiGeneraliDocumento> |
| 121 | <TipoDocumento>{{ doc.type_of_document }}</TipoDocumento> |
| 122 | <Divisa>EUR</Divisa> |
| 123 | <Data>{{ doc.posting_date }}</Data> |
| 124 | <Numero>{{ doc.unamended_name }}</Numero> |
| 125 | {%- if doc.stamp_duty %} |
| 126 | <DatiBollo> |
| 127 | <BolloVirtuale>SI</BolloVirtuale> |
| 128 | <ImportoBollo>{{ format_float(doc.stamp_duty) }}</ImportoBollo> |
| 129 | </DatiBollo> |
| 130 | {%- endif %} |
| 131 | <ImportoTotaleDocumento>{{ format_float(doc.grand_total) }}</ImportoTotaleDocumento> |
| 132 | <Causale>VENDITA</Causale> |
| 133 | </DatiGeneraliDocumento> |
| 134 | {%- if doc.po_no %} |
| 135 | <DatiOrdineAcquisto> |
| 136 | <IdDocumento>{{ doc.po_no }}</IdDocumento> |
| 137 | {%- if doc.po_date %} |
| 138 | <Data>{{ doc.po_date }}</Data> |
| 139 | {%- endif %} |
| 140 | </DatiOrdineAcquisto> |
| 141 | {%- endif %} |
| 142 | {%- if doc.is_return and doc.return_against_unamended %} |
| 143 | <DatiFattureCollegate> |
| 144 | <IdDocumento>{{ doc.return_against_unamended }}</IdDocumento> |
| 145 | </DatiFattureCollegate> |
| 146 | {%- endif %} |
| 147 | {%- if doc.shipping_address_data %} |
| 148 | <DatiTrasporto> |
| 149 | <IndirizzoResa> |
| 150 | {{ render_address(doc.shipping_address_data) }} |
| 151 | </IndirizzoResa> |
| 152 | </DatiTrasporto> |
| 153 | {%- endif %} |
| 154 | </DatiGenerali> |
| 155 | <DatiBeniServizi> |
Gaurav | 2670ad7 | 2019-02-19 10:17:17 +0530 | [diff] [blame] | 156 | {%- for item in doc.e_invoice_items %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 157 | <DettaglioLinee> |
| 158 | <NumeroLinea>{{ item.idx }}</NumeroLinea> |
| 159 | <CodiceArticolo> |
| 160 | <CodiceTipo>CODICE</CodiceTipo> |
| 161 | <CodiceValore>{{ item.item_code }}</CodiceValore> |
| 162 | </CodiceArticolo> |
Rohit Waghchaure | 0f98cb8 | 2019-02-26 15:01:30 +0530 | [diff] [blame] | 163 | <Descrizione>{{ html2text(item.description) or item.item_name }}</Descrizione> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 164 | <Quantita>{{ format_float(item.qty) }}</Quantita> |
| 165 | <UnitaMisura>{{ item.stock_uom }}</UnitaMisura> |
| 166 | <PrezzoUnitario>{{ format_float(item.price_list_rate or item.rate) }}</PrezzoUnitario> |
| 167 | {{ render_discount_or_margin(item) }} |
| 168 | <PrezzoTotale>{{ format_float(item.amount) }}</PrezzoTotale> |
| 169 | <AliquotaIVA>{{ format_float(item.tax_rate) }}</AliquotaIVA> |
| 170 | {%- if item.tax_exemption_reason %} |
| 171 | <Natura>{{ item.tax_exemption_reason.split("-")[0] }}</Natura> |
| 172 | {%- endif %} |
| 173 | </DettaglioLinee> |
| 174 | {%- endfor %} |
| 175 | {%- for tax, data in doc.tax_data.items() %} |
| 176 | <DatiRiepilogo> |
| 177 | <AliquotaIVA>{{ format_float(tax|flt) }}</AliquotaIVA> |
| 178 | {%- if data.tax_exemption_reason %} |
| 179 | <Natura>{{ data.tax_exemption_reason.split("-")[0] }}</Natura> |
| 180 | {%- endif %} |
| 181 | <ImponibileImporto>{{ format_float(data.taxable_amount) }}</ImponibileImporto> |
| 182 | <Imposta>{{ format_float(data.tax_amount) }}</Imposta> |
| 183 | <EsigibilitaIVA>{{ doc.vat_collectability.split("-")[0] }}</EsigibilitaIVA> |
| 184 | {%- if data.tax_exemption_law %} |
| 185 | <RiferimentoNormativo>{{ data.tax_exemption_law }}</RiferimentoNormativo> |
| 186 | {%- endif %} |
| 187 | </DatiRiepilogo> |
| 188 | {%- endfor %} |
| 189 | </DatiBeniServizi> |
| 190 | {%- if doc.payment_schedule %} |
| 191 | <DatiPagamento> |
| 192 | {%- if payment_schedule|length > 1 %} |
| 193 | <CondizioniPagamento>TP01</CondizioniPagamento> |
| 194 | {%- else %} |
| 195 | <CondizioniPagamento>TP02</CondizioniPagamento> |
| 196 | {%- endif %} |
| 197 | {%- for payment_term in doc.payment_schedule %} |
| 198 | <DettaglioPagamento> |
| 199 | <ModalitaPagamento>{{ payment_term.mode_of_payment_code.split("-")[0] }}</ModalitaPagamento> |
| 200 | <DataScadenzaPagamento>{{ payment_term.due_date }}</DataScadenzaPagamento> |
| 201 | <ImportoPagamento>{{ format_float(payment_term.payment_amount) }}</ImportoPagamento> |
| 202 | {%- if payment_term.bank_account_iban %}<IBAN>{{ payment_term.bank_account_iban }}</IBAN>{%- endif %} |
| 203 | </DettaglioPagamento> |
| 204 | {%- endfor %} |
| 205 | </DatiPagamento> |
| 206 | {%- endif %} |
| 207 | </FatturaElettronicaBody> |
| 208 | </p:FatturaElettronica> |