Skip to content

Commit

Permalink
(fix): Fix operaciones exoneradas/inafectas & Add homologacion tests (#…
Browse files Browse the repository at this point in the history
…169)

* - Add homologacion tests
- Fix operaciones exoneradas/inafectas

* Remove group4
  • Loading branch information
carlosthe19916 authored Jan 7, 2023
1 parent 19ac28a commit d41f952
Show file tree
Hide file tree
Showing 59 changed files with 10,844 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class DocumentoVentaDetalle {
private String precioReferenciaTipo;

// Impuestos
@Schema(description = "Ejemplo: 0.18", minimum = "0", maximum = "1")
private BigDecimal tasaIgv;

@Schema(description = "Monto total de IGV", minimum = "0")
private BigDecimal igv;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public void modify(Object object) {
if (detalle.getIgvTipo() == null) {
catalog7 = Catalog7.GRAVADO_OPERACION_ONEROSA;
} else {
catalog7 =
Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
}

detalle.setIgvTipo(catalog7.getCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 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.apache.org/licenses/LICENSE-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.xbuilder.enricher.kie.rules.enrich.body.detalle;

import io.github.project.openubl.xbuilder.content.catalogs.Catalog;
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
import io.github.project.openubl.xbuilder.enricher.kie.AbstractBodyRule;
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;

import java.math.BigDecimal;
import java.util.function.Consumer;

import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.isSalesDocumentItem;
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.whenSalesDocumentItem;

@RulePhase(type = RulePhase.PhaseType.ENRICH)
public class TasaIgvRule extends AbstractBodyRule {

@Override
public boolean test(Object object) {
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
.map(documento -> documento.getTasaIgv() == null && documento.getIgvTipo() != null)
.orElse(false)
);
}

@Override
public void modify(Object object) {
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
BigDecimal igvTasa;
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
switch (catalog7.getGrupo()) {
case EXPORTACION:
case EXONERADO:
case INAFECTO: {
igvTasa = BigDecimal.ZERO;
break;
}
default: {
igvTasa = getRuleContext().getTasaIgv();
break;
}
}
detalle.setTasaIgv(igvTasa);
};
whenSalesDocumentItem.apply(object).ifPresent(consumer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class TasaIgvRule extends AbstractHeaderRule {

@Override
public boolean test(Object object) {
return (
isSalesDocument.test(object) &&
whenSalesDocument.apply(object).map(documento -> documento.getTasaIgv() == null).orElse(false)
return (isSalesDocument.test(object) && whenSalesDocument.apply(object)
.map(documento -> documento.getTasaIgv() == null)
.orElse(false)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package io.github.project.openubl.xbuilder.enricher.kie.rules.process.body.detalle;

import io.github.project.openubl.xbuilder.content.catalogs.Catalog;
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
import io.github.project.openubl.xbuilder.enricher.kie.AbstractBodyRule;
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;
Expand All @@ -31,26 +33,28 @@ public class IgvBaseImponibleRule extends AbstractBodyRule {

@Override
public boolean test(Object object) {
return (
isSalesDocumentItem.test(object) &&
whenSalesDocumentItem
.apply(object)
.map(documento ->
documento.getIgvBaseImponible() == null &&
documento.getCantidad() != null &&
documento.getPrecio() != null &&
documento.getPrecioReferencia() != null
)
.orElse(false)
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
.map(documento -> documento.getIgvBaseImponible() == null &&
documento.getIgvTipo() != null &&
documento.getCantidad() != null &&
documento.getPrecio() != null &&
documento.getPrecioReferencia() != null
)
.orElse(false)
);
}

@Override
public void modify(Object object) {
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
BigDecimal baseImponible = !detalle.isPrecioConImpuestos()
? detalle.getCantidad().multiply(detalle.getPrecio())
: detalle.getCantidad().multiply(detalle.getPrecioReferencia());
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);

BigDecimal baseImponible;
if (catalog7.isOperacionOnerosa()) {
baseImponible = detalle.getCantidad().multiply(detalle.getPrecio());
} else {
baseImponible = detalle.getCantidad().multiply(detalle.getPrecioReferencia());
}
detalle.setIgvBaseImponible(baseImponible);
};
whenSalesDocumentItem.apply(object).ifPresent(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public class IgvRule extends AbstractBodyRule {

@Override
public boolean test(Object object) {
return (
isSalesDocumentItem.test(object) &&
whenSalesDocumentItem
.apply(object)
.map(documento -> documento.getIgv() == null && documento.getIgvBaseImponible() != null)
.orElse(false)
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
.map(documento -> documento.getIgv() == null &&
documento.getIgvBaseImponible() != null &&
documento.getTasaIgv() != null
)
.orElse(false)
);
}

@Override
public void modify(Object object) {
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
BigDecimal igv = detalle.getIgvBaseImponible().multiply(getRuleContext().getTasaIgv());
BigDecimal igv = detalle.getIgvBaseImponible().multiply(detalle.getTasaIgv());
detalle.setIgv(igv);
};
whenSalesDocumentItem.apply(object).ifPresent(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.function.Consumer;

import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.isSalesDocumentItem;
Expand All @@ -34,16 +33,13 @@ public class PrecioDeReferenciaRule extends AbstractBodyRule {

@Override
public boolean test(Object object) {
return (
isSalesDocumentItem.test(object) &&
whenSalesDocumentItem
.apply(object)
.map(documento ->
documento.getPrecioReferencia() == null &&
documento.getPrecio() != null &&
documento.getIgvTipo() != null
)
.orElse(false)
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
.map(documento -> documento.getPrecioReferencia() == null &&
documento.getPrecio() != null &&
documento.getTasaIgv() != null &&
documento.getIgvTipo() != null
)
.orElse(false)
);
}

Expand All @@ -55,18 +51,14 @@ public void modify(Object object) {
.orElseThrow(Catalog.invalidCatalogValue);

BigDecimal precioReferencia;
if (detalle.isPrecioConImpuestos()) {
precioReferencia =
catalog7.isOperacionOnerosa()
? detalle
.getPrecio()
.divide(getRuleContext().getTasaIgv().add(BigDecimal.ONE), 10, RoundingMode.HALF_EVEN)
: detalle.getPrecio();
if (catalog7.isOperacionOnerosa()) {
if (detalle.isPrecioConImpuestos()) {
precioReferencia = detalle.getPrecio();
} else {
precioReferencia = detalle.getPrecio().multiply(detalle.getTasaIgv().add(BigDecimal.ONE));
}
} else {
precioReferencia =
catalog7.isOperacionOnerosa()
? detalle.getPrecio().multiply(getRuleContext().getTasaIgv().add(BigDecimal.ONE))
: detalle.getPrecio();
precioReferencia = detalle.getPrecio();
}

detalle.setPrecioReferencia(precioReferencia);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License - 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.apache.org/licenses/LICENSE-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.xbuilder.enricher.kie.rules.process.body.detalle;

import io.github.project.openubl.xbuilder.content.catalogs.Catalog;
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
import io.github.project.openubl.xbuilder.enricher.kie.AbstractBodyRule;
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.function.Consumer;

import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.isSalesDocumentItem;
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.whenSalesDocumentItem;

@RulePhase(type = RulePhase.PhaseType.PROCESS)
public class PrecioRule extends AbstractBodyRule {

@Override
public boolean test(Object object) {
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
.map(documento -> documento.getPrecioReferencia() != null && documento.getIgvTipo() != null)
.orElse(false)
);
}

@Override
public void modify(Object object) {
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);

BigDecimal precio;
if (catalog7.isOperacionOnerosa()) {
if (detalle.isPrecioConImpuestos()) {
precio = detalle.getPrecioReferencia().divide(detalle.getTasaIgv().add(BigDecimal.ONE), 10, RoundingMode.HALF_EVEN);;
} else {
precio = detalle.getPrecio();
}
} else {
precio = BigDecimal.ZERO;
}

detalle.setPrecio(precio);
};
whenSalesDocumentItem.apply(object).ifPresent(consumer);
}
}
Loading

0 comments on commit d41f952

Please sign in to comment.