Skip to content

Commit 6baa47f

Browse files
Enhance default codigo local (#29)
1 parent b6bad36 commit 6baa47f

File tree

3 files changed

+296
-5
lines changed

3 files changed

+296
-5
lines changed

src/main/java/io/github/project/openubl/xmlbuilderlib/factory/common/ProveedorOutputModelFactory.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,24 @@ private ProveedorOutputModelFactory() {
2828
}
2929

3030
public static ProveedorOutputModel getProveedor(ProveedorInputModel input) {
31+
DireccionOutputModel direccionOutput = input.getDireccion() != null ?
32+
DireccionOutputModelFactory.getDireccion(input.getDireccion()) :
33+
new DireccionOutputModel();
34+
enrichDireccionOutput(direccionOutput);
35+
3136
return ProveedorOutputModel.Builder.aProveedorOutputModel()
3237
.withRuc(input.getRuc())
3338
.withRazonSocial(input.getRazonSocial())
3439
.withNombreComercial(input.getNombreComercial())
35-
.withDireccion(input.getDireccion() != null ? DireccionOutputModelFactory.getDireccion(input.getDireccion()) : getDefaultDireccion())
40+
.withDireccion(direccionOutput)
3641
.withContacto(input.getContacto() != null ? ContactoOutputModelFactory.getContacto(input.getContacto()) : null)
3742
.build();
3843

3944
}
4045

41-
private static DireccionOutputModel getDefaultDireccion() {
42-
return DireccionOutputModel.Builder.aDireccionOutputModel()
43-
.withCodigoLocal(Constants.DEFAULT_CODIGO_LOCAL)
44-
.build();
46+
private static void enrichDireccionOutput(DireccionOutputModel direccionOutput) {
47+
if (direccionOutput.getCodigoLocal() == null) {
48+
direccionOutput.setCodigoLocal(Constants.DEFAULT_CODIGO_LOCAL);
49+
}
4550
}
4651
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/invoice/InvoiceTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,57 @@ void testInvoiceWithICB_precioConIgv() throws Exception {
384384
assertSnapshot(xml, "xml/invoice/icb.xml");
385385
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
386386
}
387+
388+
@Test
389+
void testInvoiceWithCustomProveedor_direccionNotNullAndCodigoLocalNull() throws Exception {
390+
// Given
391+
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
392+
.withSerie("F001")
393+
.withNumero(1)
394+
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
395+
.withRuc("12345678912")
396+
.withRazonSocial("Project OpenUBL S.A.C.")
397+
.withDireccion(DireccionInputModel.Builder.aDireccionInputModel()
398+
.withDireccion("Jr. las flores 123")
399+
.build()
400+
)
401+
.build()
402+
)
403+
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
404+
.withNombre("Carlos Feria")
405+
.withNumeroDocumentoIdentidad("12121212121")
406+
.withTipoDocumentoIdentidad(Catalog6.RUC.toString())
407+
.build()
408+
)
409+
.withFirmante(FirmanteInputModel.Builder.aFirmanteInputModel()
410+
.withRuc("000000000000")
411+
.withRazonSocial("Wolsnut4 S.A.C.")
412+
.build()
413+
)
414+
.withDetalle(Arrays.asList(
415+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
416+
.withDescripcion("Item1")
417+
.withCantidad(new BigDecimal(10))
418+
.withPrecioConIgv(new BigDecimal(118))
419+
.withIcb(true)
420+
.build(),
421+
DocumentLineInputModel.Builder.aDocumentLineInputModel()
422+
.withDescripcion("Item2")
423+
.withCantidad(new BigDecimal(10))
424+
.withPrecioConIgv(new BigDecimal(118))
425+
.withIcb(true)
426+
.build())
427+
)
428+
.build();
429+
430+
// When
431+
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, config, systemClock);
432+
InvoiceOutputModel output = result.getOutput();
433+
String xml = result.getXml();
434+
435+
// Then
436+
assertOutputHasNoConstraintViolations(validator, output);
437+
assertSnapshot(xml, "xml/invoice/customCodigoLocal.xml");
438+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
439+
}
387440
}
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-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+
<ext:UBLExtensions>
14+
<ext:UBLExtension>
15+
<ext:ExtensionContent/>
16+
</ext:UBLExtension>
17+
</ext:UBLExtensions>
18+
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
19+
<cbc:CustomizationID>2.0</cbc:CustomizationID>
20+
<cbc:ID>F001-1</cbc:ID>
21+
<cbc:IssueDate>2019-12-24</cbc:IssueDate>
22+
<cbc:IssueTime>20:30:59</cbc:IssueTime>
23+
<cbc:InvoiceTypeCode listID="0101" listAgencyName="PE:SUNAT" listName="Tipo de Documento"
24+
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01">01
25+
</cbc:InvoiceTypeCode>
26+
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe"
27+
listName="Currency">PEN
28+
</cbc:DocumentCurrencyCode>
29+
<cac:Signature>
30+
<cbc:ID>000000000000</cbc:ID>
31+
<cac:SignatoryParty>
32+
<cac:PartyIdentification>
33+
<cbc:ID>000000000000</cbc:ID>
34+
</cac:PartyIdentification>
35+
<cac:PartyName>
36+
<cbc:Name><![CDATA[Wolsnut4 S.A.C.]]></cbc:Name>
37+
</cac:PartyName>
38+
</cac:SignatoryParty>
39+
<cac:DigitalSignatureAttachment>
40+
<cac:ExternalReference>
41+
<cbc:URI>#PROJECT-OPENUBL-SIGN</cbc:URI>
42+
</cac:ExternalReference>
43+
</cac:DigitalSignatureAttachment>
44+
</cac:Signature>
45+
<cac:AccountingSupplierParty>
46+
<cac:Party>
47+
<cac:PartyIdentification>
48+
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad"
49+
schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12345678912
50+
</cbc:ID>
51+
</cac:PartyIdentification>
52+
<cac:PartyLegalEntity>
53+
<cbc:RegistrationName><![CDATA[Project OpenUBL S.A.C.]]></cbc:RegistrationName>
54+
<cac:RegistrationAddress>
55+
<cbc:AddressTypeCode>0000</cbc:AddressTypeCode>
56+
<cac:AddressLine>
57+
<cbc:Line><![CDATA[Jr. las flores 123]]></cbc:Line>
58+
</cac:AddressLine>
59+
</cac:RegistrationAddress>
60+
</cac:PartyLegalEntity>
61+
</cac:Party>
62+
</cac:AccountingSupplierParty>
63+
<cac:AccountingCustomerParty>
64+
<cac:Party>
65+
<cac:PartyIdentification>
66+
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad"
67+
schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12121212121
68+
</cbc:ID>
69+
</cac:PartyIdentification>
70+
<cac:PartyLegalEntity>
71+
<cbc:RegistrationName><![CDATA[Carlos Feria]]></cbc:RegistrationName>
72+
</cac:PartyLegalEntity>
73+
</cac:Party>
74+
</cac:AccountingCustomerParty>
75+
<cac:PaymentTerms>
76+
<cbc:ID>FormaPago</cbc:ID>
77+
<cbc:PaymentMeansID>Contado</cbc:PaymentMeansID>
78+
<cbc:Amount currencyID="PEN">2364</cbc:Amount>
79+
</cac:PaymentTerms>
80+
<cac:TaxTotal>
81+
<cbc:TaxAmount currencyID="PEN">364</cbc:TaxAmount>
82+
<cac:TaxSubtotal>
83+
<cbc:TaxableAmount currencyID="PEN">2000</cbc:TaxableAmount>
84+
<cbc:TaxAmount currencyID="PEN">360</cbc:TaxAmount>
85+
<cac:TaxCategory>
86+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
87+
schemeName="Tax Category Identifie">S
88+
</cbc:ID>
89+
<cac:TaxScheme>
90+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">1000
91+
</cbc:ID>
92+
<cbc:Name>IGV</cbc:Name>
93+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
94+
</cac:TaxScheme>
95+
</cac:TaxCategory>
96+
</cac:TaxSubtotal>
97+
<cac:TaxSubtotal>
98+
<cbc:TaxAmount currencyID="PEN">4</cbc:TaxAmount>
99+
<cac:TaxCategory>
100+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
101+
schemeName="Tax Category Identifie">S
102+
</cbc:ID>
103+
<cac:TaxScheme>
104+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">7152
105+
</cbc:ID>
106+
<cbc:Name>ICBPER</cbc:Name>
107+
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
108+
</cac:TaxScheme>
109+
</cac:TaxCategory>
110+
</cac:TaxSubtotal>
111+
</cac:TaxTotal>
112+
<cac:LegalMonetaryTotal>
113+
<cbc:LineExtensionAmount currencyID="PEN">2000</cbc:LineExtensionAmount>
114+
<cbc:TaxInclusiveAmount currencyID="PEN">2364</cbc:TaxInclusiveAmount>
115+
<cbc:PayableAmount currencyID="PEN">2364</cbc:PayableAmount>
116+
</cac:LegalMonetaryTotal>
117+
<cac:InvoiceLine>
118+
<cbc:ID>1</cbc:ID>
119+
<cbc:InvoicedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe"
120+
unitCodeListID="UN/ECE rec 20">10
121+
</cbc:InvoicedQuantity>
122+
<cbc:LineExtensionAmount currencyID="PEN">1000</cbc:LineExtensionAmount>
123+
<cac:PricingReference>
124+
<cac:AlternativeConditionPrice>
125+
<cbc:PriceAmount currencyID="PEN">118</cbc:PriceAmount>
126+
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio"
127+
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01
128+
</cbc:PriceTypeCode>
129+
</cac:AlternativeConditionPrice>
130+
</cac:PricingReference>
131+
<cac:TaxTotal>
132+
<cbc:TaxAmount currencyID="PEN">182</cbc:TaxAmount>
133+
<cac:TaxSubtotal>
134+
<cbc:TaxableAmount currencyID="PEN">1000</cbc:TaxableAmount>
135+
<cbc:TaxAmount currencyID="PEN">180</cbc:TaxAmount>
136+
<cac:TaxCategory>
137+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
138+
schemeName="Tax Category Identifier">S
139+
</cbc:ID>
140+
<cbc:Percent>18</cbc:Percent>
141+
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV"
142+
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10
143+
</cbc:TaxExemptionReasonCode>
144+
<cac:TaxScheme>
145+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
146+
1000
147+
</cbc:ID>
148+
<cbc:Name>IGV</cbc:Name>
149+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
150+
</cac:TaxScheme>
151+
</cac:TaxCategory>
152+
</cac:TaxSubtotal>
153+
<cac:TaxSubtotal>
154+
<cbc:TaxAmount currencyID="PEN">2</cbc:TaxAmount>
155+
<cbc:BaseUnitMeasure unitCode="NIU">10</cbc:BaseUnitMeasure>
156+
<cac:TaxCategory>
157+
<cbc:PerUnitAmount currencyID="PEN">0.2</cbc:PerUnitAmount>
158+
<cac:TaxScheme>
159+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
160+
7152
161+
</cbc:ID>
162+
<cbc:Name>ICBPER</cbc:Name>
163+
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
164+
</cac:TaxScheme>
165+
</cac:TaxCategory>
166+
</cac:TaxSubtotal>
167+
</cac:TaxTotal>
168+
<cac:Item>
169+
<cbc:Description><![CDATA[Item1]]></cbc:Description>
170+
</cac:Item>
171+
<cac:Price>
172+
<cbc:PriceAmount currencyID="PEN">100</cbc:PriceAmount>
173+
</cac:Price>
174+
</cac:InvoiceLine>
175+
<cac:InvoiceLine>
176+
<cbc:ID>2</cbc:ID>
177+
<cbc:InvoicedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe"
178+
unitCodeListID="UN/ECE rec 20">10
179+
</cbc:InvoicedQuantity>
180+
<cbc:LineExtensionAmount currencyID="PEN">1000</cbc:LineExtensionAmount>
181+
<cac:PricingReference>
182+
<cac:AlternativeConditionPrice>
183+
<cbc:PriceAmount currencyID="PEN">118</cbc:PriceAmount>
184+
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio"
185+
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01
186+
</cbc:PriceTypeCode>
187+
</cac:AlternativeConditionPrice>
188+
</cac:PricingReference>
189+
<cac:TaxTotal>
190+
<cbc:TaxAmount currencyID="PEN">182</cbc:TaxAmount>
191+
<cac:TaxSubtotal>
192+
<cbc:TaxableAmount currencyID="PEN">1000</cbc:TaxableAmount>
193+
<cbc:TaxAmount currencyID="PEN">180</cbc:TaxAmount>
194+
<cac:TaxCategory>
195+
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
196+
schemeName="Tax Category Identifier">S
197+
</cbc:ID>
198+
<cbc:Percent>18</cbc:Percent>
199+
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV"
200+
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10
201+
</cbc:TaxExemptionReasonCode>
202+
<cac:TaxScheme>
203+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
204+
1000
205+
</cbc:ID>
206+
<cbc:Name>IGV</cbc:Name>
207+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
208+
</cac:TaxScheme>
209+
</cac:TaxCategory>
210+
</cac:TaxSubtotal>
211+
<cac:TaxSubtotal>
212+
<cbc:TaxAmount currencyID="PEN">2</cbc:TaxAmount>
213+
<cbc:BaseUnitMeasure unitCode="NIU">10</cbc:BaseUnitMeasure>
214+
<cac:TaxCategory>
215+
<cbc:PerUnitAmount currencyID="PEN">0.2</cbc:PerUnitAmount>
216+
<cac:TaxScheme>
217+
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
218+
7152
219+
</cbc:ID>
220+
<cbc:Name>ICBPER</cbc:Name>
221+
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
222+
</cac:TaxScheme>
223+
</cac:TaxCategory>
224+
</cac:TaxSubtotal>
225+
</cac:TaxTotal>
226+
<cac:Item>
227+
<cbc:Description><![CDATA[Item2]]></cbc:Description>
228+
</cac:Item>
229+
<cac:Price>
230+
<cbc:PriceAmount currencyID="PEN">100</cbc:PriceAmount>
231+
</cac:Price>
232+
</cac:InvoiceLine>
233+
</Invoice>

0 commit comments

Comments
 (0)