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 %} |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 12 | <Nazione>{{ address.country_code }}</Nazione> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 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> |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 43 | <IdPaese>{{ doc.company_address_data.country_code }}</IdPaese> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 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> |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 59 | <IdPaese>{{ doc.company_address_data.country_code }}</IdPaese> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 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 %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 98 | <IdFiscaleIVA> |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 99 | <IdPaese>{{ doc.customer_address_data.country_code }}</IdPaese> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 100 | <IdCodice>{{ doc.tax_id | replace("IT","") }}</IdCodice> |
| 101 | </IdFiscaleIVA> |
Himanshu | 138e030 | 2019-03-22 23:22:52 +0530 | [diff] [blame] | 102 | {%- if doc.customer_data.fiscal_code %} |
| 103 | <CodiceFiscale>{{ doc.customer_data.fiscal_code }}</CodiceFiscale> |
| 104 | {%- endif %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 105 | <Anagrafica> |
| 106 | <Denominazione>{{ doc.customer_name }}</Denominazione> |
| 107 | </Anagrafica> |
| 108 | {%- endif %} |
| 109 | </DatiAnagrafici> |
| 110 | {%- if doc.customer_address_data %} |
| 111 | <Sede> |
| 112 | {{ render_address(doc.customer_address_data) }} |
| 113 | </Sede> |
| 114 | {%- endif %} |
| 115 | </CessionarioCommittente> |
| 116 | </FatturaElettronicaHeader> |
| 117 | <FatturaElettronicaBody> |
| 118 | <DatiGenerali> |
| 119 | <DatiGeneraliDocumento> |
| 120 | <TipoDocumento>{{ doc.type_of_document }}</TipoDocumento> |
| 121 | <Divisa>EUR</Divisa> |
| 122 | <Data>{{ doc.posting_date }}</Data> |
| 123 | <Numero>{{ doc.unamended_name }}</Numero> |
| 124 | {%- if doc.stamp_duty %} |
| 125 | <DatiBollo> |
| 126 | <BolloVirtuale>SI</BolloVirtuale> |
| 127 | <ImportoBollo>{{ format_float(doc.stamp_duty) }}</ImportoBollo> |
| 128 | </DatiBollo> |
| 129 | {%- endif %} |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 130 | {%- if doc.discount_amount %} |
| 131 | <ScontoMaggiorazione> |
| 132 | {%- if doc.discount_amount > 0.0 %} |
| 133 | <Tipo>SC</Tipo> |
| 134 | {%- else %} |
| 135 | <Tipo>MG</Tipo> |
| 136 | {%- endif %} |
| 137 | {%- if doc.additional_discount_percentage > 0.0 %} |
| 138 | <Percentuale>{{ format_float(doc.additional_discount_percentage) }}</Percentuale> |
| 139 | {%- endif %} |
| 140 | <Importo>{{ format_float(doc.discount_amount) }}</Importo> |
| 141 | </ScontoMaggiorazione> |
| 142 | {%- endif %} |
| 143 | <ImportoTotaleDocumento>{{ format_float(doc.rounded_total or doc.grand_total) }}</ImportoTotaleDocumento> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 144 | <Causale>VENDITA</Causale> |
| 145 | </DatiGeneraliDocumento> |
Rohit Waghchaure | 1b7059b | 2019-03-12 17:44:29 +0530 | [diff] [blame] | 146 | {%- for po_no, po_date in doc.customer_po_data.items() %} |
| 147 | <DatiOrdineAcquisto> |
| 148 | <IdDocumento>{{ po_no }}</IdDocumento> |
| 149 | <Data>{{ po_date }}</Data> |
| 150 | </DatiOrdineAcquisto> |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 151 | {%- endfor %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 152 | {%- if doc.is_return and doc.return_against_unamended %} |
| 153 | <DatiFattureCollegate> |
| 154 | <IdDocumento>{{ doc.return_against_unamended }}</IdDocumento> |
| 155 | </DatiFattureCollegate> |
| 156 | {%- endif %} |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 157 | {%- for row in doc.e_invoice_items %} |
| 158 | {%- if row.delivery_note %} |
| 159 | <DatiDDT> |
| 160 | <NumeroDDT>{{ row.delivery_note }}</NumeroDDT> |
| 161 | <DataDDT>{{ frappe.db.get_value('Delivery Note', row.delivery_note, 'posting_date') }}</DataDDT> |
| 162 | <RiferimentoNumeroLinea>{{ row.idx }}</RiferimentoNumeroLinea> |
| 163 | </DatiDDT> |
| 164 | {%- endif %} |
| 165 | {%- endfor %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 166 | {%- if doc.shipping_address_data %} |
| 167 | <DatiTrasporto> |
| 168 | <IndirizzoResa> |
| 169 | {{ render_address(doc.shipping_address_data) }} |
| 170 | </IndirizzoResa> |
| 171 | </DatiTrasporto> |
| 172 | {%- endif %} |
| 173 | </DatiGenerali> |
| 174 | <DatiBeniServizi> |
Gaurav | 2670ad7 | 2019-02-19 10:17:17 +0530 | [diff] [blame] | 175 | {%- for item in doc.e_invoice_items %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 176 | <DettaglioLinee> |
| 177 | <NumeroLinea>{{ item.idx }}</NumeroLinea> |
| 178 | <CodiceArticolo> |
| 179 | <CodiceTipo>CODICE</CodiceTipo> |
| 180 | <CodiceValore>{{ item.item_code }}</CodiceValore> |
| 181 | </CodiceArticolo> |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 182 | <Descrizione>{{ html2text(item.description or '') or item.item_name }}</Descrizione> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 183 | <Quantita>{{ format_float(item.qty) }}</Quantita> |
| 184 | <UnitaMisura>{{ item.stock_uom }}</UnitaMisura> |
| 185 | <PrezzoUnitario>{{ format_float(item.price_list_rate or item.rate) }}</PrezzoUnitario> |
| 186 | {{ render_discount_or_margin(item) }} |
Rohit Waghchaure | a2f71cd | 2019-04-03 16:10:14 +0530 | [diff] [blame] | 187 | <PrezzoTotale>{{ format_float(item.amount) }}</PrezzoTotale> |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 188 | <AliquotaIVA>{{ format_float(item.tax_rate) }}</AliquotaIVA> |
| 189 | {%- if item.tax_exemption_reason %} |
| 190 | <Natura>{{ item.tax_exemption_reason.split("-")[0] }}</Natura> |
| 191 | {%- endif %} |
| 192 | </DettaglioLinee> |
| 193 | {%- endfor %} |
| 194 | {%- for tax, data in doc.tax_data.items() %} |
| 195 | <DatiRiepilogo> |
| 196 | <AliquotaIVA>{{ format_float(tax|flt) }}</AliquotaIVA> |
| 197 | {%- if data.tax_exemption_reason %} |
| 198 | <Natura>{{ data.tax_exemption_reason.split("-")[0] }}</Natura> |
| 199 | {%- endif %} |
| 200 | <ImponibileImporto>{{ format_float(data.taxable_amount) }}</ImponibileImporto> |
| 201 | <Imposta>{{ format_float(data.tax_amount) }}</Imposta> |
| 202 | <EsigibilitaIVA>{{ doc.vat_collectability.split("-")[0] }}</EsigibilitaIVA> |
| 203 | {%- if data.tax_exemption_law %} |
| 204 | <RiferimentoNormativo>{{ data.tax_exemption_law }}</RiferimentoNormativo> |
| 205 | {%- endif %} |
| 206 | </DatiRiepilogo> |
| 207 | {%- endfor %} |
| 208 | </DatiBeniServizi> |
| 209 | {%- if doc.payment_schedule %} |
| 210 | <DatiPagamento> |
| 211 | {%- if payment_schedule|length > 1 %} |
| 212 | <CondizioniPagamento>TP01</CondizioniPagamento> |
| 213 | {%- else %} |
| 214 | <CondizioniPagamento>TP02</CondizioniPagamento> |
| 215 | {%- endif %} |
| 216 | {%- for payment_term in doc.payment_schedule %} |
| 217 | <DettaglioPagamento> |
| 218 | <ModalitaPagamento>{{ payment_term.mode_of_payment_code.split("-")[0] }}</ModalitaPagamento> |
| 219 | <DataScadenzaPagamento>{{ payment_term.due_date }}</DataScadenzaPagamento> |
| 220 | <ImportoPagamento>{{ format_float(payment_term.payment_amount) }}</ImportoPagamento> |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 221 | {%- if payment_term.bank_account_name %} |
| 222 | <IstitutoFinanziario>{{ payment_term.bank_account_name }}</IstitutoFinanziario> |
| 223 | {%- endif %} |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 224 | {%- if payment_term.bank_account_iban %} |
| 225 | <IBAN>{{ payment_term.bank_account_iban }}</IBAN> |
| 226 | <ABI>{{ payment_term.bank_account_iban[5:10] }}</ABI> |
| 227 | <CAB>{{ payment_term.bank_account_iban[10:15] }}</CAB> |
| 228 | {%- endif %} |
| 229 | {%- if payment_term.bank_account_swift_number %} |
| 230 | <BIC>{{ payment_term.bank_account_swift_number }}</BIC> |
| 231 | {%- endif %} |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 232 | </DettaglioPagamento> |
| 233 | {%- endfor %} |
| 234 | </DatiPagamento> |
| 235 | {%- endif %} |
| 236 | </FatturaElettronicaBody> |
| 237 | </p:FatturaElettronica> |