Skip to content

Commit d41f952

Browse files
(fix): Fix operaciones exoneradas/inafectas & Add homologacion tests (#169)
* - Add homologacion tests - Fix operaciones exoneradas/inafectas * Remove group4
1 parent 19ac28a commit d41f952

File tree

59 files changed

+10844
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+10844
-133
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class DocumentoVentaDetalle {
5151
private String precioReferenciaTipo;
5252

5353
// Impuestos
54+
@Schema(description = "Ejemplo: 0.18", minimum = "0", maximum = "1")
55+
private BigDecimal tasaIgv;
56+
5457
@Schema(description = "Monto total de IGV", minimum = "0")
5558
private BigDecimal igv;
5659

core/src/main/java/io/github/project/openubl/xbuilder/enricher/kie/rules/enrich/body/detalle/IgvTipoRule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public void modify(Object object) {
4242
if (detalle.getIgvTipo() == null) {
4343
catalog7 = Catalog7.GRAVADO_OPERACION_ONEROSA;
4444
} else {
45-
catalog7 =
46-
Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
45+
catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
4746
}
4847

4948
detalle.setIgvTipo(catalog7.getCode());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 io.github.project.openubl.xbuilder.enricher.kie.rules.enrich.body.detalle;
18+
19+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog;
20+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
21+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
22+
import io.github.project.openubl.xbuilder.enricher.kie.AbstractBodyRule;
23+
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;
24+
25+
import java.math.BigDecimal;
26+
import java.util.function.Consumer;
27+
28+
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.isSalesDocumentItem;
29+
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.whenSalesDocumentItem;
30+
31+
@RulePhase(type = RulePhase.PhaseType.ENRICH)
32+
public class TasaIgvRule extends AbstractBodyRule {
33+
34+
@Override
35+
public boolean test(Object object) {
36+
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
37+
.map(documento -> documento.getTasaIgv() == null && documento.getIgvTipo() != null)
38+
.orElse(false)
39+
);
40+
}
41+
42+
@Override
43+
public void modify(Object object) {
44+
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
45+
BigDecimal igvTasa;
46+
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
47+
switch (catalog7.getGrupo()) {
48+
case EXPORTACION:
49+
case EXONERADO:
50+
case INAFECTO: {
51+
igvTasa = BigDecimal.ZERO;
52+
break;
53+
}
54+
default: {
55+
igvTasa = getRuleContext().getTasaIgv();
56+
break;
57+
}
58+
}
59+
detalle.setTasaIgv(igvTasa);
60+
};
61+
whenSalesDocumentItem.apply(object).ifPresent(consumer);
62+
}
63+
}

core/src/main/java/io/github/project/openubl/xbuilder/enricher/kie/rules/enrich/header/TasaIgvRule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class TasaIgvRule extends AbstractHeaderRule {
3030

3131
@Override
3232
public boolean test(Object object) {
33-
return (
34-
isSalesDocument.test(object) &&
35-
whenSalesDocument.apply(object).map(documento -> documento.getTasaIgv() == null).orElse(false)
33+
return (isSalesDocument.test(object) && whenSalesDocument.apply(object)
34+
.map(documento -> documento.getTasaIgv() == null)
35+
.orElse(false)
3636
);
3737
}
3838

core/src/main/java/io/github/project/openubl/xbuilder/enricher/kie/rules/process/body/detalle/IgvBaseImponibleRule.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package io.github.project.openubl.xbuilder.enricher.kie.rules.process.body.detalle;
1818

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

3234
@Override
3335
public boolean test(Object object) {
34-
return (
35-
isSalesDocumentItem.test(object) &&
36-
whenSalesDocumentItem
37-
.apply(object)
38-
.map(documento ->
39-
documento.getIgvBaseImponible() == null &&
40-
documento.getCantidad() != null &&
41-
documento.getPrecio() != null &&
42-
documento.getPrecioReferencia() != null
43-
)
44-
.orElse(false)
36+
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
37+
.map(documento -> documento.getIgvBaseImponible() == null &&
38+
documento.getIgvTipo() != null &&
39+
documento.getCantidad() != null &&
40+
documento.getPrecio() != null &&
41+
documento.getPrecioReferencia() != null
42+
)
43+
.orElse(false)
4544
);
4645
}
4746

4847
@Override
4948
public void modify(Object object) {
5049
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
51-
BigDecimal baseImponible = !detalle.isPrecioConImpuestos()
52-
? detalle.getCantidad().multiply(detalle.getPrecio())
53-
: detalle.getCantidad().multiply(detalle.getPrecioReferencia());
50+
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
51+
52+
BigDecimal baseImponible;
53+
if (catalog7.isOperacionOnerosa()) {
54+
baseImponible = detalle.getCantidad().multiply(detalle.getPrecio());
55+
} else {
56+
baseImponible = detalle.getCantidad().multiply(detalle.getPrecioReferencia());
57+
}
5458
detalle.setIgvBaseImponible(baseImponible);
5559
};
5660
whenSalesDocumentItem.apply(object).ifPresent(consumer);

core/src/main/java/io/github/project/openubl/xbuilder/enricher/kie/rules/process/body/detalle/IgvRule.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ public class IgvRule extends AbstractBodyRule {
3131

3232
@Override
3333
public boolean test(Object object) {
34-
return (
35-
isSalesDocumentItem.test(object) &&
36-
whenSalesDocumentItem
37-
.apply(object)
38-
.map(documento -> documento.getIgv() == null && documento.getIgvBaseImponible() != null)
39-
.orElse(false)
34+
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
35+
.map(documento -> documento.getIgv() == null &&
36+
documento.getIgvBaseImponible() != null &&
37+
documento.getTasaIgv() != null
38+
)
39+
.orElse(false)
4040
);
4141
}
4242

4343
@Override
4444
public void modify(Object object) {
4545
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
46-
BigDecimal igv = detalle.getIgvBaseImponible().multiply(getRuleContext().getTasaIgv());
46+
BigDecimal igv = detalle.getIgvBaseImponible().multiply(detalle.getTasaIgv());
4747
detalle.setIgv(igv);
4848
};
4949
whenSalesDocumentItem.apply(object).ifPresent(consumer);

core/src/main/java/io/github/project/openubl/xbuilder/enricher/kie/rules/process/body/detalle/PrecioDeReferenciaRule.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;
2424

2525
import java.math.BigDecimal;
26-
import java.math.RoundingMode;
2726
import java.util.function.Consumer;
2827

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

3534
@Override
3635
public boolean test(Object object) {
37-
return (
38-
isSalesDocumentItem.test(object) &&
39-
whenSalesDocumentItem
40-
.apply(object)
41-
.map(documento ->
42-
documento.getPrecioReferencia() == null &&
43-
documento.getPrecio() != null &&
44-
documento.getIgvTipo() != null
45-
)
46-
.orElse(false)
36+
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
37+
.map(documento -> documento.getPrecioReferencia() == null &&
38+
documento.getPrecio() != null &&
39+
documento.getTasaIgv() != null &&
40+
documento.getIgvTipo() != null
41+
)
42+
.orElse(false)
4743
);
4844
}
4945

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

5753
BigDecimal precioReferencia;
58-
if (detalle.isPrecioConImpuestos()) {
59-
precioReferencia =
60-
catalog7.isOperacionOnerosa()
61-
? detalle
62-
.getPrecio()
63-
.divide(getRuleContext().getTasaIgv().add(BigDecimal.ONE), 10, RoundingMode.HALF_EVEN)
64-
: detalle.getPrecio();
54+
if (catalog7.isOperacionOnerosa()) {
55+
if (detalle.isPrecioConImpuestos()) {
56+
precioReferencia = detalle.getPrecio();
57+
} else {
58+
precioReferencia = detalle.getPrecio().multiply(detalle.getTasaIgv().add(BigDecimal.ONE));
59+
}
6560
} else {
66-
precioReferencia =
67-
catalog7.isOperacionOnerosa()
68-
? detalle.getPrecio().multiply(getRuleContext().getTasaIgv().add(BigDecimal.ONE))
69-
: detalle.getPrecio();
61+
precioReferencia = detalle.getPrecio();
7062
}
7163

7264
detalle.setPrecioReferencia(precioReferencia);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 io.github.project.openubl.xbuilder.enricher.kie.rules.process.body.detalle;
18+
19+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog;
20+
import io.github.project.openubl.xbuilder.content.catalogs.Catalog7;
21+
import io.github.project.openubl.xbuilder.content.models.standard.general.DocumentoVentaDetalle;
22+
import io.github.project.openubl.xbuilder.enricher.kie.AbstractBodyRule;
23+
import io.github.project.openubl.xbuilder.enricher.kie.RulePhase;
24+
25+
import java.math.BigDecimal;
26+
import java.math.RoundingMode;
27+
import java.util.function.Consumer;
28+
29+
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.isSalesDocumentItem;
30+
import static io.github.project.openubl.xbuilder.enricher.kie.rules.utils.Helpers.whenSalesDocumentItem;
31+
32+
@RulePhase(type = RulePhase.PhaseType.PROCESS)
33+
public class PrecioRule extends AbstractBodyRule {
34+
35+
@Override
36+
public boolean test(Object object) {
37+
return (isSalesDocumentItem.test(object) && whenSalesDocumentItem.apply(object)
38+
.map(documento -> documento.getPrecioReferencia() != null && documento.getIgvTipo() != null)
39+
.orElse(false)
40+
);
41+
}
42+
43+
@Override
44+
public void modify(Object object) {
45+
Consumer<DocumentoVentaDetalle> consumer = detalle -> {
46+
Catalog7 catalog7 = Catalog.valueOfCode(Catalog7.class, detalle.getIgvTipo()).orElseThrow(Catalog.invalidCatalogValue);
47+
48+
BigDecimal precio;
49+
if (catalog7.isOperacionOnerosa()) {
50+
if (detalle.isPrecioConImpuestos()) {
51+
precio = detalle.getPrecioReferencia().divide(detalle.getTasaIgv().add(BigDecimal.ONE), 10, RoundingMode.HALF_EVEN);;
52+
} else {
53+
precio = detalle.getPrecio();
54+
}
55+
} else {
56+
precio = BigDecimal.ZERO;
57+
}
58+
59+
detalle.setPrecio(precio);
60+
};
61+
whenSalesDocumentItem.apply(object).ifPresent(consumer);
62+
}
63+
}

0 commit comments

Comments
 (0)