Skip to content

Enhance default codigo local #29

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 1 commit into from
Apr 6, 2021
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 @@ -28,19 +28,24 @@ private ProveedorOutputModelFactory() {
}

public static ProveedorOutputModel getProveedor(ProveedorInputModel input) {
DireccionOutputModel direccionOutput = input.getDireccion() != null ?
DireccionOutputModelFactory.getDireccion(input.getDireccion()) :
new DireccionOutputModel();
enrichDireccionOutput(direccionOutput);

return ProveedorOutputModel.Builder.aProveedorOutputModel()
.withRuc(input.getRuc())
.withRazonSocial(input.getRazonSocial())
.withNombreComercial(input.getNombreComercial())
.withDireccion(input.getDireccion() != null ? DireccionOutputModelFactory.getDireccion(input.getDireccion()) : getDefaultDireccion())
.withDireccion(direccionOutput)
.withContacto(input.getContacto() != null ? ContactoOutputModelFactory.getContacto(input.getContacto()) : null)
.build();

}

private static DireccionOutputModel getDefaultDireccion() {
return DireccionOutputModel.Builder.aDireccionOutputModel()
.withCodigoLocal(Constants.DEFAULT_CODIGO_LOCAL)
.build();
private static void enrichDireccionOutput(DireccionOutputModel direccionOutput) {
if (direccionOutput.getCodigoLocal() == null) {
direccionOutput.setCodigoLocal(Constants.DEFAULT_CODIGO_LOCAL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,57 @@ void testInvoiceWithICB_precioConIgv() throws Exception {
assertSnapshot(xml, "xml/invoice/icb.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}

@Test
void testInvoiceWithCustomProveedor_direccionNotNullAndCodigoLocalNull() throws Exception {
// Given
InvoiceInputModel input = InvoiceInputModel.Builder.anInvoiceInputModel()
.withSerie("F001")
.withNumero(1)
.withProveedor(ProveedorInputModel.Builder.aProveedorInputModel()
.withRuc("12345678912")
.withRazonSocial("Project OpenUBL S.A.C.")
.withDireccion(DireccionInputModel.Builder.aDireccionInputModel()
.withDireccion("Jr. las flores 123")
.build()
)
.build()
)
.withCliente(ClienteInputModel.Builder.aClienteInputModel()
.withNombre("Carlos Feria")
.withNumeroDocumentoIdentidad("12121212121")
.withTipoDocumentoIdentidad(Catalog6.RUC.toString())
.build()
)
.withFirmante(FirmanteInputModel.Builder.aFirmanteInputModel()
.withRuc("000000000000")
.withRazonSocial("Wolsnut4 S.A.C.")
.build()
)
.withDetalle(Arrays.asList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(new BigDecimal(10))
.withPrecioConIgv(new BigDecimal(118))
.withIcb(true)
.build(),
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item2")
.withCantidad(new BigDecimal(10))
.withPrecioConIgv(new BigDecimal(118))
.withIcb(true)
.build())
)
.build();

// When
DocumentWrapper<InvoiceOutputModel> result = DocumentManager.createXML(input, config, systemClock);
InvoiceOutputModel output = result.getOutput();
String xml = result.getXml();

// Then
assertOutputHasNoConstraintViolations(validator, output);
assertSnapshot(xml, "xml/invoice/customCodigoLocal.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}
}
233 changes: 233 additions & 0 deletions src/test/resources/xml/invoice/customCodigoLocal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ccts="urn:un:unece:uncefact:documentation:2"
xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent/>
</ext:UBLExtension>
</ext:UBLExtensions>
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:CustomizationID>2.0</cbc:CustomizationID>
<cbc:ID>F001-1</cbc:ID>
<cbc:IssueDate>2019-12-24</cbc:IssueDate>
<cbc:IssueTime>20:30:59</cbc:IssueTime>
<cbc:InvoiceTypeCode listID="0101" listAgencyName="PE:SUNAT" listName="Tipo de Documento"
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01">01
</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyName="United Nations Economic Commission for Europe"
listName="Currency">PEN
</cbc:DocumentCurrencyCode>
<cac:Signature>
<cbc:ID>000000000000</cbc:ID>
<cac:SignatoryParty>
<cac:PartyIdentification>
<cbc:ID>000000000000</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name><![CDATA[Wolsnut4 S.A.C.]]></cbc:Name>
</cac:PartyName>
</cac:SignatoryParty>
<cac:DigitalSignatureAttachment>
<cac:ExternalReference>
<cbc:URI>#PROJECT-OPENUBL-SIGN</cbc:URI>
</cac:ExternalReference>
</cac:DigitalSignatureAttachment>
</cac:Signature>
<cac:AccountingSupplierParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad"
schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12345678912
</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[Project OpenUBL S.A.C.]]></cbc:RegistrationName>
<cac:RegistrationAddress>
<cbc:AddressTypeCode>0000</cbc:AddressTypeCode>
<cac:AddressLine>
<cbc:Line><![CDATA[Jr. las flores 123]]></cbc:Line>
</cac:AddressLine>
</cac:RegistrationAddress>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="6" schemeAgencyName="PE:SUNAT" schemeName="Documento de Identidad"
schemeURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo06">12121212121
</cbc:ID>
</cac:PartyIdentification>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[Carlos Feria]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingCustomerParty>
<cac:PaymentTerms>
<cbc:ID>FormaPago</cbc:ID>
<cbc:PaymentMeansID>Contado</cbc:PaymentMeansID>
<cbc:Amount currencyID="PEN">2364</cbc:Amount>
</cac:PaymentTerms>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="PEN">364</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="PEN">2000</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="PEN">360</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
schemeName="Tax Category Identifie">S
</cbc:ID>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">1000
</cbc:ID>
<cbc:Name>IGV</cbc:Name>
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
<cac:TaxSubtotal>
<cbc:TaxAmount currencyID="PEN">4</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
schemeName="Tax Category Identifie">S
</cbc:ID>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">7152
</cbc:ID>
<cbc:Name>ICBPER</cbc:Name>
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:LegalMonetaryTotal>
<cbc:LineExtensionAmount currencyID="PEN">2000</cbc:LineExtensionAmount>
<cbc:TaxInclusiveAmount currencyID="PEN">2364</cbc:TaxInclusiveAmount>
<cbc:PayableAmount currencyID="PEN">2364</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
<cac:InvoiceLine>
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe"
unitCodeListID="UN/ECE rec 20">10
</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="PEN">1000</cbc:LineExtensionAmount>
<cac:PricingReference>
<cac:AlternativeConditionPrice>
<cbc:PriceAmount currencyID="PEN">118</cbc:PriceAmount>
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio"
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01
</cbc:PriceTypeCode>
</cac:AlternativeConditionPrice>
</cac:PricingReference>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="PEN">182</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="PEN">1000</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="PEN">180</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
schemeName="Tax Category Identifier">S
</cbc:ID>
<cbc:Percent>18</cbc:Percent>
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV"
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10
</cbc:TaxExemptionReasonCode>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
1000
</cbc:ID>
<cbc:Name>IGV</cbc:Name>
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
<cac:TaxSubtotal>
<cbc:TaxAmount currencyID="PEN">2</cbc:TaxAmount>
<cbc:BaseUnitMeasure unitCode="NIU">10</cbc:BaseUnitMeasure>
<cac:TaxCategory>
<cbc:PerUnitAmount currencyID="PEN">0.2</cbc:PerUnitAmount>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
7152
</cbc:ID>
<cbc:Name>ICBPER</cbc:Name>
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:Item>
<cbc:Description><![CDATA[Item1]]></cbc:Description>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="PEN">100</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cbc:ID>2</cbc:ID>
<cbc:InvoicedQuantity unitCode="NIU" unitCodeListAgencyName="United Nations Economic Commission for Europe"
unitCodeListID="UN/ECE rec 20">10
</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="PEN">1000</cbc:LineExtensionAmount>
<cac:PricingReference>
<cac:AlternativeConditionPrice>
<cbc:PriceAmount currencyID="PEN">118</cbc:PriceAmount>
<cbc:PriceTypeCode listAgencyName="PE:SUNAT" listName="Tipo de Precio"
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo16">01
</cbc:PriceTypeCode>
</cac:AlternativeConditionPrice>
</cac:PricingReference>
<cac:TaxTotal>
<cbc:TaxAmount currencyID="PEN">182</cbc:TaxAmount>
<cac:TaxSubtotal>
<cbc:TaxableAmount currencyID="PEN">1000</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="PEN">180</cbc:TaxAmount>
<cac:TaxCategory>
<cbc:ID schemeAgencyName="United Nations Economic Commission for Europe" schemeID="UN/ECE 5305"
schemeName="Tax Category Identifier">S
</cbc:ID>
<cbc:Percent>18</cbc:Percent>
<cbc:TaxExemptionReasonCode listAgencyName="PE:SUNAT" listName="Afectacion del IGV"
listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo07">10
</cbc:TaxExemptionReasonCode>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
1000
</cbc:ID>
<cbc:Name>IGV</cbc:Name>
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
<cac:TaxSubtotal>
<cbc:TaxAmount currencyID="PEN">2</cbc:TaxAmount>
<cbc:BaseUnitMeasure unitCode="NIU">10</cbc:BaseUnitMeasure>
<cac:TaxCategory>
<cbc:PerUnitAmount currencyID="PEN">0.2</cbc:PerUnitAmount>
<cac:TaxScheme>
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">
7152
</cbc:ID>
<cbc:Name>ICBPER</cbc:Name>
<cbc:TaxTypeCode>OTH</cbc:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
<cac:Item>
<cbc:Description><![CDATA[Item2]]></cbc:Description>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="PEN">100</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
</Invoice>