Skip to content

fix: xml generation set CDATA string as raw content #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
import io.quarkus.qute.Engine;
import io.quarkus.qute.HtmlEscaper;
import io.quarkus.qute.RawString;
import io.quarkus.qute.ReflectionValueResolver;
import io.quarkus.qute.TemplateLocator.TemplateLocation;
import io.quarkus.qute.ValueResolver;
Expand Down Expand Up @@ -54,6 +55,15 @@ public class EngineProducer {
.removeStandaloneLines(true)
.addResultMapper(new HtmlEscaper(List.of("text/html", "text/xml", "application/xml", "application/xhtml+xml")))
.addValueResolver(new ReflectionValueResolver())
.addValueResolver(ValueResolver.builder()
.applyToBaseClass(String.class)
.applyToName("raw")
.resolveSync(ctx -> {
String value = ((String) ctx.getBase());
return new RawString(value);
})
.build()
)
.addValueResolver(ValueResolver.builder()
.applyToBaseClass(LocalDate.class)
.applyToName("format")
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/Renderer/creditNote.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{#include ubl/standard/include/ubl-extensions.xml /}
{#include ubl/standard/include/general-data.xml item=this /}
{#for key in leyendas.keySet}
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
{/for}
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
{#include "ubl/standard/include/note/invoice-reference.xml" item=this /}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/Renderer/debitNote.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{#include ubl/standard/include/ubl-extensions.xml /}
{#include ubl/standard/include/general-data.xml item=this /}
{#for key in leyendas.keySet}
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
{/for}
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
{#include "ubl/standard/include/note/invoice-reference.xml" item=this /}
Expand Down
14 changes: 8 additions & 6 deletions core/src/main/resources/templates/Renderer/despatchAdvice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{#include ubl/standard/include/general-data.xml item=this /}
<cbc:DespatchAdviceTypeCode>{tipoComprobante}</cbc:DespatchAdviceTypeCode>
{#if observaciones}
<cbc:Note><![CDATA[{observaciones}]]></cbc:Note>
<cbc:Note><![CDATA[{observaciones.raw}]]></cbc:Note>
{/if}
{#if documentoBaja}
<cac:OrderReference>
Expand All @@ -31,7 +31,7 @@
<cbc:ID schemeID="6" schemeName="Documento de Identidad" schemeAgencyName="PE:SUNAT" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{remitente.ruc}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{remitente.razonSocial}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{remitente.razonSocial.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:DespatchSupplierParty>
Expand All @@ -41,7 +41,7 @@
<cbc:ID schemeID="{destinatario.tipoDocumentoIdentidad}" schemeName="Documento de Identidad" schemeAgencyName="PE:SUNAT" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{destinatario.numeroDocumentoIdentidad}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{destinatario.nombre}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{destinatario.nombre.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:DeliveryCustomerParty>
Expand All @@ -50,7 +50,7 @@
<cbc:CustomerAssignedAccountID schemeID="6">{proveedor.ruc}</cbc:CustomerAssignedAccountID>
<cac:Party>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:SellerSupplierParty>
Expand All @@ -77,7 +77,7 @@
<cbc:ID schemeID="{envio.transportista.tipoDocumentoIdentidad}">{envio.transportista.numeroDocumentoIdentidad}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name><![CDATA[{envio.transportista.nombre}]]></cbc:Name>
<cbc:Name><![CDATA[{envio.transportista.nombre.raw}]]></cbc:Name>
</cac:PartyName>
</cac:CarrierParty>
<cac:TransportMeans>
Expand Down Expand Up @@ -123,7 +123,9 @@
<cbc:LineID>{it_index.add(1)}</cbc:LineID>
</cac:OrderLineReference>
<cac:Item>
<cbc:Name><![CDATA[{it.descripcion}]]></cbc:Name>
{#if it.descripcion}
<cbc:Name><![CDATA[{it.descripcion.raw}]]></cbc:Name>
{/if}
<cac:SellersItemIdentification>
<cbc:ID>{it.codigo}</cbc:ID>
</cac:SellersItemIdentification>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/templates/Renderer/invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<cbc:InvoiceTypeCode listID="{tipoOperacion}" listAgencyName="PE:SUNAT" listName="Tipo de Documento" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01">{tipoComprobante}</cbc:InvoiceTypeCode>
{#if leyendas}
{#for key in leyendas.keySet}
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key).raw}]]></cbc:Note>
{/for}
{/if}
{#if observaciones}
<cbc:Note><![CDATA[{observaciones}]]></cbc:Note>
<cbc:Note><![CDATA[{observaciones.raw}]]></cbc:Note>
{/if}
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
{#if ordenDeCompra}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/Renderer/perception.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<sac:SUNATPerceptionSystemCode>{tipoRegimen}</sac:SUNATPerceptionSystemCode>
<sac:SUNATPerceptionPercent>{tipoRegimenPorcentaje}</sac:SUNATPerceptionPercent>
{#if observacion}
<cbc:Note><![CDATA[{observacion}]]></cbc:Note>
<cbc:Note><![CDATA[{observacion.raw}]]></cbc:Note>
{/if}
<cbc:TotalInvoiceAmount currencyID="{moneda}">{importeTotalPercibido}</cbc:TotalInvoiceAmount>
<sac:SUNATTotalCashed currencyID="{moneda}">{importeTotalCobrado}</sac:SUNATTotalCashed>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/Renderer/retention.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<sac:SUNATRetentionSystemCode>{tipoRegimen}</sac:SUNATRetentionSystemCode>
<sac:SUNATRetentionPercent>{tipoRegimenPorcentaje}</sac:SUNATRetentionPercent>
{#if observacion}
<cbc:Note><![CDATA[{observacion}]]></cbc:Note>
<cbc:Note><![CDATA[{observacion.raw}]]></cbc:Note>
{/if}
<cbc:TotalInvoiceAmount currencyID="{moneda}">{importeTotalRetenido}</cbc:TotalInvoiceAmount>
<sac:SUNATTotalPaid currencyID="{moneda}">{importeTotalPagado}</sac:SUNATTotalPaid>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/templates/ubl/common/signature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<cbc:ID>{firmante.ruc}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name><![CDATA[{firmante.razonSocial}]]></cbc:Name>
<cbc:Name><![CDATA[{firmante.razonSocial.raw}]]></cbc:Name>
</cac:PartyName>
</cac:SignatoryParty>
<cac:DigitalSignatureAttachment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{/if}
{#if direccion.direccion}
<cac:AddressLine>
<cbc:Line><![CDATA[{direccion.direccion}]]></cbc:Line>
<cbc:Line><![CDATA[{direccion.direccion.raw}]]></cbc:Line>
</cac:AddressLine>
{/if}
{#if direccion.codigoPais}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<cbc:ID schemeID="{cliente.tipoDocumentoIdentidad}" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">{cliente.numeroDocumentoIdentidad}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{cliente.nombre}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{cliente.nombre.raw}]]></cbc:RegistrationName>
{#if cliente.direccion}
<cac:RegistrationAddress>
{#include ubl/standard/include/address.xml direccion=cliente.direccion /}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<cbc:TaxableAmount currencyID="{moneda}">{item.iscBaseImponible.scale(2)}</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="{moneda}">{item.isc.scale(2)}</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:Percent>{item.tasaIsc.multiply(100)}</cbc:Percent>
<cbc:Percent>{item.tasaIsc.multiply(100).scale(2)}</cbc:Percent>
<cbc:TierRange>{item.iscTipo}</cbc:TierRange>
<cac:TaxScheme>
<cbc:ID>2000</cbc:ID>
Expand Down Expand Up @@ -56,7 +56,7 @@
{/if}
</cac:TaxTotal>
<cac:Item>
<cbc:Description><![CDATA[{item.descripcion}]]></cbc:Description>
<cbc:Description><![CDATA[{item.descripcion.raw}]]></cbc:Description>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="{moneda}">{item.precio.scale(2)}</cbc:PriceAmount>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<cac:DiscrepancyResponse>
<cbc:ReferenceID>{item.comprobanteAfectadoSerieNumero}</cbc:ReferenceID>
<cbc:ResponseCode>{item.comprobanteAfectadoTipo}</cbc:ResponseCode>
<cbc:Description><![CDATA[{item.sustentoDescripcion}]]></cbc:Description>
<cbc:Description><![CDATA[{item.sustentoDescripcion.raw}]]></cbc:Description>
</cac:DiscrepancyResponse>
{#if item.ordenDeCompra}
<cac:OrderReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</cac:PartyName>
{/if}
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
{#if proveedor.direccion}
<cac:RegistrationAddress>
{#include ubl/standard/include/address.xml direccion=proveedor.direccion /}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</cac:PartyIdentification>
{#if proveedor.nombreComercial}
<cac:PartyName>
<cbc:Name><![CDATA[{proveedor.nombreComercial}]]></cbc:Name>
<cbc:Name><![CDATA[{proveedor.nombreComercial.raw}]]></cbc:Name>
</cac:PartyName>
{/if}
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:AgentParty>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<cbc:ID schemeID="{cliente.tipoDocumentoIdentidad}">{cliente.numeroDocumentoIdentidad}</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{cliente.nombre}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{cliente.nombre.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:ReceiverParty>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
<cac:Party>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial}]]></cbc:RegistrationName>
<cbc:RegistrationName><![CDATA[{proveedor.razonSocial.raw}]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
<cbc:LineID>1</cbc:LineID>
</cac:OrderLineReference>
<cac:Item>
<cbc:Name><![CDATA[]]></cbc:Name>
<cac:SellersItemIdentification>
<cbc:ID>123456</cbc:ID>
</cac:SellersItemIdentification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ public void testDespatchAdvice() {
" <cbc:LineID>1</cbc:LineID>\n" +
" </cac:OrderLineReference>\n" +
" <cac:Item>\n" +
" <cbc:Name><![CDATA[]]></cbc:Name>\n" +
" <cac:SellersItemIdentification>\n" +
" <cbc:ID>123456</cbc:ID>\n" +
" </cac:SellersItemIdentification>\n" +
Expand Down