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