Skip to content

Commit e4b8290

Browse files
Add orden de compra (#82)
1 parent b461d55 commit e4b8290

File tree

9 files changed

+511
-3
lines changed

9 files changed

+511
-3
lines changed

src/main/java/io/github/project/openubl/xbuilder/content/models/standard/general/CargoDescuento.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424

2525
@Data
2626
@SuperBuilder
27-
@EqualsAndHashCode(callSuper = true)
28-
@ToString(callSuper = true)
29-
public class CargoDescuento extends BaseDocumentoTributarioRelacionado {
27+
public class CargoDescuento {
3028

29+
private String serieNumero;
3130
private String tipo;
3231
private BigDecimal monto;
3332
private BigDecimal porcentaje;

src/main/java/io/github/project/openubl/xbuilder/content/models/standard/general/Document.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public abstract class Document {
7373
*/
7474
private LocalTime horaEmision;
7575

76+
/**
77+
* Orden de compra
78+
*/
79+
private String ordenDeCompra;
80+
7681
/**
7782
* Cliente
7883
*/

src/main/java/io/github/project/openubl/xbuilder/content/models/standard/general/Invoice.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Invoice extends Document {
3333

3434
private LocalDate fechaVencimiento;
3535
private String tipoComprobante;
36+
private String observaciones;
3637

3738
/**
3839
* Catalog51

src/main/resources/templates/Renderer/invoice.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
{#for key in leyendas.keySet}
1212
<cbc:Note languageLocaleID="{key}"><![CDATA[{leyendas.get(key)}]]></cbc:Note>
1313
{/for}
14+
{#if observaciones}
15+
<cbc:Note><![CDATA[{observaciones}]]></cbc:Note>
16+
{/if}
1417
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">{moneda}</cbc:DocumentCurrencyCode>
18+
{#if ordenDeCompra}
19+
<cac:OrderReference>
20+
<cbc:ID>{ordenDeCompra}</cbc:ID>
21+
</cac:OrderReference>
22+
{/if}
1523
{#each anticipos.orEmpty}
1624
<cac:AdditionalDocumentReference>
1725
<cbc:ID>{it.comprobanteSerieNumero}</cbc:ID>

src/main/resources/templates/ubl/standard/include/note/invoice-reference.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<cbc:ResponseCode>{item.comprobanteAfectadoTipo}</cbc:ResponseCode>
44
<cbc:Description><![CDATA[{item.sustentoDescripcion}]]></cbc:Description>
55
</cac:DiscrepancyResponse>
6+
{#if item.ordenDeCompra}
7+
<cac:OrderReference>
8+
<cbc:ID>{item.ordenDeCompra}</cbc:ID>
9+
</cac:OrderReference>
10+
{/if}
611
<cac:BillingReference>
712
<cac:InvoiceDocumentReference>
813
<cbc:ID>{item.comprobanteAfectadoSerieNumero}</cbc:ID>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package e2e.renderer.creditnote;
18+
19+
import static e2e.renderer.XMLAssertUtils.assertSendSunat;
20+
import static e2e.renderer.XMLAssertUtils.assertSnapshot;
21+
22+
import e2e.AbstractTest;
23+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog6;
24+
import io.github.project.openubl.xbuilder.content.models.common.Cliente;
25+
import io.github.project.openubl.xbuilder.content.models.common.Proveedor;
26+
import io.github.project.openubl.xbuilder.content.models.standard.general.CreditNote;
27+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoDetalle;
28+
import io.github.project.openubl.xbuilder.enricher.ContentEnricher;
29+
import io.github.project.openubl.xbuilder.renderer.TemplateProducer;
30+
import io.quarkus.qute.Template;
31+
import java.math.BigDecimal;
32+
import org.junit.jupiter.api.Test;
33+
34+
public class CreditNoteOrdenDeCompraTest extends AbstractTest {
35+
36+
@Test
37+
public void testInvoiceWithCustomUnidadMedida() throws Exception {
38+
// Given
39+
CreditNote input = CreditNote
40+
.builder()
41+
.serie("FC01")
42+
.numero(1)
43+
.comprobanteAfectadoSerieNumero("F001-1")
44+
.sustentoDescripcion("mi sustento")
45+
.ordenDeCompra("123456")
46+
.proveedor(Proveedor.builder().ruc("12345678912").razonSocial("Softgreen S.A.C.").build())
47+
.cliente(
48+
Cliente
49+
.builder()
50+
.nombre("Carlos Feria")
51+
.numeroDocumentoIdentidad("12121212121")
52+
.tipoDocumentoIdentidad(Catalog6.RUC.toString())
53+
.build()
54+
)
55+
.detalle(
56+
DocumentoDetalle
57+
.builder()
58+
.descripcion("Item1")
59+
.cantidad(new BigDecimal("10"))
60+
.precio(new BigDecimal("100"))
61+
.build()
62+
)
63+
.detalle(
64+
DocumentoDetalle
65+
.builder()
66+
.descripcion("Item2")
67+
.cantidad(new BigDecimal("10"))
68+
.precio(new BigDecimal("100"))
69+
.build()
70+
)
71+
.build();
72+
73+
ContentEnricher enricher = new ContentEnricher(defaults, dateProvider);
74+
enricher.enrich(input);
75+
76+
// When
77+
Template template = TemplateProducer.getInstance().getCreditNote();
78+
String xml = template.data(input).render();
79+
80+
// Then
81+
assertSnapshot(xml, getClass(), "ordenDeCompra.xml");
82+
assertSendSunat(xml);
83+
}
84+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Apache License - 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package e2e.renderer.invoice;
18+
19+
import e2e.AbstractTest;
20+
import e2e.renderer.XMLAssertUtils;
21+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog6;
22+
import io.github.project.openubl.xbuilder.content.models.common.Cliente;
23+
import io.github.project.openubl.xbuilder.content.models.common.Proveedor;
24+
import io.github.project.openubl.xbuilder.content.models.standard.general.Anticipo;
25+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoDetalle;
26+
import io.github.project.openubl.xbuilder.content.models.standard.general.Invoice;
27+
import io.github.project.openubl.xbuilder.enricher.ContentEnricher;
28+
import io.github.project.openubl.xbuilder.renderer.TemplateProducer;
29+
import io.quarkus.qute.Template;
30+
import java.math.BigDecimal;
31+
import org.junit.jupiter.api.Test;
32+
33+
public class InvoiceOrdeDeCompraTest extends AbstractTest {
34+
35+
@Test
36+
public void testFechaVencimiento() throws Exception {
37+
// Given
38+
Invoice input = Invoice
39+
.builder()
40+
.serie("F001")
41+
.numero(1)
42+
.ordenDeCompra("123456")
43+
.proveedor(Proveedor.builder().ruc("12345678912").razonSocial("Softgreen S.A.C.").build())
44+
.cliente(
45+
Cliente
46+
.builder()
47+
.nombre("Carlos Feria")
48+
.numeroDocumentoIdentidad("12121212121")
49+
.tipoDocumentoIdentidad(Catalog6.RUC.toString())
50+
.build()
51+
)
52+
.detalle(
53+
DocumentoDetalle
54+
.builder()
55+
.descripcion("Item1")
56+
.cantidad(new BigDecimal("2"))
57+
.precio(new BigDecimal("100"))
58+
.build()
59+
)
60+
.detalle(
61+
DocumentoDetalle
62+
.builder()
63+
.descripcion("Item2")
64+
.cantidad(new BigDecimal("2"))
65+
.precio(new BigDecimal("100"))
66+
.build()
67+
)
68+
.build();
69+
70+
ContentEnricher enricher = new ContentEnricher(defaults, dateProvider);
71+
enricher.enrich(input);
72+
73+
// When
74+
Template template = TemplateProducer.getInstance().getInvoice();
75+
String xml = template.data(input).render();
76+
77+
// Then
78+
XMLAssertUtils.assertSnapshot(xml, getClass(), "ordenDeCompra.xml");
79+
XMLAssertUtils.assertSendSunat(xml);
80+
}
81+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
3+
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
4+
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
5+
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
6+
xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
7+
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
8+
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
9+
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
10+
xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1"
11+
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
12+
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13+
>
14+
<ext:UBLExtensions>
15+
<ext:UBLExtension>
16+
<ext:ExtensionContent/>
17+
</ext:UBLExtension>
18+
</ext:UBLExtensions>
19+
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
20+
<cbc:CustomizationID>2.0</cbc:CustomizationID>
21+
<cbc:ID>FC01-1</cbc:ID>
22+
<cbc:IssueDate>2019-12-24</cbc:IssueDate>
23+
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe" listName="Currency">PEN</cbc:DocumentCurrencyCode>
24+
<cac:DiscrepancyResponse>
25+
<cbc:ReferenceID>F001-1</cbc:ReferenceID>
26+
<cbc:ResponseCode>01</cbc:ResponseCode>
27+
<cbc:Description><![CDATA[mi sustento]]></cbc:Description>
28+
</cac:DiscrepancyResponse>
29+
<cac:OrderReference>
30+
<cbc:ID>123456</cbc:ID>
31+
</cac:OrderReference>
32+
<cac:BillingReference>
33+
<cac:InvoiceDocumentReference>
34+
<cbc:ID>F001-1</cbc:ID>
35+
<cbc:DocumentTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Documento" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01">01</cbc:DocumentTypeCode>
36+
</cac:InvoiceDocumentReference>
37+
</cac:BillingReference>
38+
<cac:Signature>
39+
<cbc:ID>12345678912</cbc:ID>
40+
<cac:SignatoryParty>
41+
<cac:PartyIdentification>
42+
<cbc:ID>12345678912</cbc:ID>
43+
</cac:PartyIdentification>
44+
<cac:PartyName>
45+
<cbc:Name><![CDATA[Softgreen S.A.C.]]></cbc:Name>
46+
</cac:PartyName>
47+
</cac:SignatoryParty>
48+
<cac:DigitalSignatureAttachment>
49+
<cac:ExternalReference>
50+
<cbc:URI>#PROJECT-OPENUBL-SIGN</cbc:URI>
51+
</cac:ExternalReference>
52+
</cac:DigitalSignatureAttachment>
53+
</cac:Signature>
54+
<cac:AccountingSupplierParty>
55+
<cac:Party>
56+
<cac:PartyIdentification>
57+
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12345678912</cbc:ID>
58+
</cac:PartyIdentification>
59+
<cac:PartyLegalEntity>
60+
<cbc:RegistrationName><![CDATA[Softgreen S.A.C.]]></cbc:RegistrationName>
61+
<cac:RegistrationAddress>
62+
<cbc:AddressTypeCode>0000</cbc:AddressTypeCode>
63+
</cac:RegistrationAddress>
64+
</cac:PartyLegalEntity>
65+
</cac:Party>
66+
</cac:AccountingSupplierParty>
67+
<cac:AccountingCustomerParty>
68+
<cac:Party>
69+
<cac:PartyIdentification>
70+
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad" schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12121212121</cbc:ID>
71+
</cac:PartyIdentification>
72+
<cac:PartyLegalEntity>
73+
<cbc:RegistrationName><![CDATA[Carlos Feria]]></cbc:RegistrationName>
74+
</cac:PartyLegalEntity>
75+
</cac:Party>
76+
</cac:AccountingCustomerParty>
77+
<cac:TaxTotal>
78+
<cbc:TaxAmount currencyID="PEN">360.00</cbc:TaxAmount>
79+
<cac:TaxSubtotal>
80+
<cbc:TaxableAmount currencyID="PEN">2000.00</cbc:TaxableAmount>
81+
<cbc:TaxAmount currencyID="PEN">360.00</cbc:TaxAmount>
82+
<cac:TaxCategory>
83+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305" schemeName="Tax Category Identifie">S</cbc:ID>
84+
<cac:TaxScheme>
85+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">1000</cbc:ID>
86+
<cbc:Name>IGV</cbc:Name>
87+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
88+
</cac:TaxScheme>
89+
</cac:TaxCategory>
90+
</cac:TaxSubtotal>
91+
</cac:TaxTotal>
92+
<cac:LegalMonetaryTotal>
93+
<cbc:LineExtensionAmount currencyID="PEN">2000.00</cbc:LineExtensionAmount>
94+
<cbc:TaxInclusiveAmount currencyID="PEN">2360.00</cbc:TaxInclusiveAmount>
95+
<cbc:PayableAmount currencyID="PEN">2360.00</cbc:PayableAmount>
96+
</cac:LegalMonetaryTotal>
97+
<cac:CreditNoteLine>
98+
<cbc:ID>1</cbc:ID>
99+
<cbc:CreditedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe" unitCodeListID="UN/ECE rec 20">10</cbc:CreditedQuantity>
100+
<cbc:LineExtensionAmount currencyID="PEN">1000.00</cbc:LineExtensionAmount>
101+
<cac:PricingReference>
102+
<cac:AlternativeConditionPrice>
103+
<cbc:PriceAmount currencyID="PEN">118.00</cbc:PriceAmount>
104+
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01</cbc:PriceTypeCode>
105+
</cac:AlternativeConditionPrice>
106+
</cac:PricingReference>
107+
<cac:TaxTotal>
108+
<cbc:TaxAmount currencyID="PEN">180.00</cbc:TaxAmount>
109+
<cac:TaxSubtotal>
110+
<cbc:TaxableAmount currencyID="PEN">1000.00</cbc:TaxableAmount>
111+
<cbc:TaxAmount currencyID="PEN">180.00</cbc:TaxAmount>
112+
<cac:TaxCategory>
113+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305" schemeName="Tax Category Identifier">S</cbc:ID>
114+
<cbc:Percent>18.00</cbc:Percent>
115+
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10</cbc:TaxExemptionReasonCode>
116+
<cac:TaxScheme>
117+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">1000</cbc:ID>
118+
<cbc:Name>IGV</cbc:Name>
119+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
120+
</cac:TaxScheme>
121+
</cac:TaxCategory>
122+
</cac:TaxSubtotal>
123+
</cac:TaxTotal>
124+
<cac:Item>
125+
<cbc:Description><![CDATA[Item1]]></cbc:Description>
126+
</cac:Item>
127+
<cac:Price>
128+
<cbc:PriceAmount currencyID="PEN">100.00</cbc:PriceAmount>
129+
</cac:Price>
130+
</cac:CreditNoteLine>
131+
<cac:CreditNoteLine>
132+
<cbc:ID>2</cbc:ID>
133+
<cbc:CreditedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe" unitCodeListID="UN/ECE rec 20">10</cbc:CreditedQuantity>
134+
<cbc:LineExtensionAmount currencyID="PEN">1000.00</cbc:LineExtensionAmount>
135+
<cac:PricingReference>
136+
<cac:AlternativeConditionPrice>
137+
<cbc:PriceAmount currencyID="PEN">118.00</cbc:PriceAmount>
138+
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01</cbc:PriceTypeCode>
139+
</cac:AlternativeConditionPrice>
140+
</cac:PricingReference>
141+
<cac:TaxTotal>
142+
<cbc:TaxAmount currencyID="PEN">180.00</cbc:TaxAmount>
143+
<cac:TaxSubtotal>
144+
<cbc:TaxableAmount currencyID="PEN">1000.00</cbc:TaxableAmount>
145+
<cbc:TaxAmount currencyID="PEN">180.00</cbc:TaxAmount>
146+
<cac:TaxCategory>
147+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305" schemeName="Tax Category Identifier">S</cbc:ID>
148+
<cbc:Percent>18.00</cbc:Percent>
149+
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10</cbc:TaxExemptionReasonCode>
150+
<cac:TaxScheme>
151+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">1000</cbc:ID>
152+
<cbc:Name>IGV</cbc:Name>
153+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
154+
</cac:TaxScheme>
155+
</cac:TaxCategory>
156+
</cac:TaxSubtotal>
157+
</cac:TaxTotal>
158+
<cac:Item>
159+
<cbc:Description><![CDATA[Item2]]></cbc:Description>
160+
</cac:Item>
161+
<cac:Price>
162+
<cbc:PriceAmount currencyID="PEN">100.00</cbc:PriceAmount>
163+
</cac:Price>
164+
</cac:CreditNoteLine>
165+
</CreditNote>

0 commit comments

Comments
 (0)