Skip to content

[ISSUE-30] La base imponible a nivel de linea difiere de la información consignada en el comprobante #31

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 4 commits into from
Apr 10, 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 @@ -53,17 +53,27 @@ public static DocumentLineOutputModel getDocumentLineOutput(DocumentLineInputMod
// Precio con/sin impuestos
BigDecimal precioUnitario;
BigDecimal precioConIgv;
BigDecimal valorVentaSinImpuestos;

if (input.getPrecioUnitario() != null) {
precioUnitario = input.getPrecioUnitario();
precioConIgv = input.getPrecioUnitario().multiply(input.getCantidad())
.add(impuestosOutput.getIgv().getImporte())
.divide(input.getCantidad(), 2, RoundingMode.HALF_EVEN);

// Valor de venta (sin impuestos)
valorVentaSinImpuestos = precioUnitario.multiply(input.getCantidad())
.setScale(2, RoundingMode.HALF_EVEN);
} else if (input.getPrecioConIgv() != null) {
precioUnitario = input.getPrecioConIgv().multiply(input.getCantidad())
.subtract(impuestosOutput.getIgv().getImporte())
.divide(input.getCantidad(), 2, RoundingMode.HALF_EVEN);
precioConIgv = input.getPrecioConIgv();

// Valor de venta (sin impuestos)
valorVentaSinImpuestos = precioConIgv.multiply(input.getCantidad())
.subtract(impuestosOutput.getIgv().getImporte())
.setScale(2, RoundingMode.HALF_EVEN);
} else {
throw new IllegalStateException("Precio con impuestos y/o sin impuestos no encontrado, no se pueden calcular el precion con impuestos");
}
Expand All @@ -74,10 +84,16 @@ public static DocumentLineOutputModel getDocumentLineOutput(DocumentLineInputMod
impuestosOutput.getIgv().getTipo().isOperacionOnerosa() ? precioUnitario : BigDecimal.ZERO
);

// Valor de venta (sin impuestos)
builder.withValorVentaSinImpuestos(valorVentaSinImpuestos);

// Precio de referencia
builder.withPrecioDeReferencia(DocumentLinePrecioReferenciaOutputModel.Builder.aDetallePrecioReferenciaOutputModel()
.withPrecio(precioConIgv)
.withPrecio(
impuestosOutput.getIgv().getTipo().isOperacionOnerosa()
? precioConIgv
: precioUnitario
)
.withTipoPrecio(
impuestosOutput.getIgv().getTipo().isOperacionOnerosa()
? Catalog16.PRECIO_UNITARIO_INCLUYE_IGV
Expand All @@ -86,14 +102,6 @@ public static DocumentLineOutputModel getDocumentLineOutput(DocumentLineInputMod
.build()
);

// Valor de venta (sin impuestos)
BigDecimal valorVentaSinImpuestos = input.getCantidad().multiply(precioConIgv).setScale(2, RoundingMode.HALF_EVEN);

if (impuestosOutput.getIgv().getTipo().isOperacionOnerosa()) {
valorVentaSinImpuestos = valorVentaSinImpuestos.subtract(impuestosOutput.getIgv().getImporte());
}
builder.withValorVentaSinImpuestos(valorVentaSinImpuestos);

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ private static void enrichDocument(DocumentInputModel input, DocumentOutputModel
// Gratuito
ImpuestoTotalOutputModel gratuito = getImpuestoTotal(lineOutput, Catalog5.GRATUITO);
if (gratuito.getBaseImponible().compareTo(BigDecimal.ZERO) > 0) {
gratuito.setImporte(BigDecimal.ZERO);
impuestosBuilder.withInafectas(gratuito);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/**
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Eclipse Public License - v 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.eclipse.org/legal/epl-2.0/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlbuilderlib.integrationtest.ubl.invoice.issues;

import io.github.project.openubl.xmlbuilderlib.facade.DocumentManager;
import io.github.project.openubl.xmlbuilderlib.facade.DocumentWrapper;
import io.github.project.openubl.xmlbuilderlib.integrationtest.AbstractUBLTest;
import io.github.project.openubl.xmlbuilderlib.models.catalogs.Catalog6;
import io.github.project.openubl.xmlbuilderlib.models.input.common.ClienteInputModel;
import io.github.project.openubl.xmlbuilderlib.models.input.common.DireccionInputModel;
import io.github.project.openubl.xmlbuilderlib.models.input.common.FirmanteInputModel;
import io.github.project.openubl.xmlbuilderlib.models.input.common.ProveedorInputModel;
import io.github.project.openubl.xmlbuilderlib.models.input.standard.DocumentLineInputModel;
import io.github.project.openubl.xmlbuilderlib.models.input.standard.invoice.InvoiceInputModel;
import io.github.project.openubl.xmlbuilderlib.models.output.standard.invoice.InvoiceOutputModel;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.Collections;

/**
* Description: La base imponible a nivel de linea difiere de la información consiganada en el comprobante
* Issue: https://github.com/project-openubl/xbuilder/issues/30
*/
public class Issue30 extends AbstractUBLTest {

public Issue30() throws Exception {
}

@Test
void testInvoice_withPrecioUnitario() 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(Collections.singletonList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(new BigDecimal("10"))
.withPrecioUnitario(new BigDecimal("6.68"))
.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/issues/issue-30-with-precioUnitario.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}

@Test
void testInvoice_withPrecioConIgv() 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(Collections.singletonList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(new BigDecimal("10"))
.withPrecioConIgv(new BigDecimal("7.88"))
.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/issues/issue-30-with-precioConIgv.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}

@Test
void testInvoice_withPrecioUnitario_andICB() 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(Collections.singletonList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(new BigDecimal("10"))
.withPrecioUnitario(new BigDecimal("6.68"))
.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/issues/issue-30-with-precioUnitario_andICB.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}

@Test
void testInvoice_withPrecioConIgv_andICB() 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(Collections.singletonList(
DocumentLineInputModel.Builder.aDocumentLineInputModel()
.withDescripcion("Item1")
.withCantidad(new BigDecimal("10"))
.withPrecioConIgv(new BigDecimal("7.88"))
.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/issues/issue-30-with-precioConIgv_andICB.xml");
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
}
}
Loading