Skip to content

Commit

Permalink
task: enhance code following clippy enhancements (project-openubl#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 authored Aug 12, 2024
1 parent 19bc2a4 commit 3d00890
Show file tree
Hide file tree
Showing 49 changed files with 440 additions and 367 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions xbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ lazy_static = { workspace = true }
serde = { workspace = true, features = ["derive"] }
rust_decimal = { workspace = true, features = ["serde-str", "serde-with-str"] }
rust_decimal_macros = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }

[dev-dependencies]
libxml = { workspace = true }
Expand Down
44 changes: 22 additions & 22 deletions xbuilder/src/enricher/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ where

while changed {
let results = [
FechaEmisionFillRule::fill(self, defaults),
FirmanteFillRule::fill(self),
IcbTasaFillRule::fill(self, defaults),
IgvTasaFillRule::fill(self, defaults),
IvapTasaFillRule::fill(self, defaults),
MonedaFillRule::fill(self),
ProveedorFillRule::fill(self),
DetallesFillRule::fill(self),
FechaEmisionFillRule::fill(self, defaults).unwrap_or_default(),
FirmanteFillRule::fill(self).unwrap_or_default(),
IcbTasaFillRule::fill(self, defaults).unwrap_or_default(),
IgvTasaFillRule::fill(self, defaults).unwrap_or_default(),
IvapTasaFillRule::fill(self, defaults).unwrap_or_default(),
MonedaFillRule::fill(self).unwrap_or_default(),
ProveedorFillRule::fill(self).unwrap_or_default(),
DetallesFillRule::fill(self).unwrap_or_default(),
];

changed = results.contains(&true);
Expand All @@ -115,16 +115,16 @@ where

while changed {
let results = [
InvoiceAnticiposFillRule::fill(self),
InvoiceDescuentosFillRule::fill(self),
InvoiceFormaDePagoFillRule::fill(self),
InvoiceFormaDePagoTotalRule::fill(self),
InvoiceFormaDePagoTipoRule::fill(self),
InvoiceLeyendaDetraccionFillRule::fill(self),
InvoiceLeyendaDireccionEntregaFillRule::fill(self),
InvoiceLeyendaPercepcionFillRule::fill(self),
InvoiceTipoComprobanteFillRule::fill(self),
InvoiceTipoOperacionFillRule::fill(self),
InvoiceAnticiposFillRule::fill(self).unwrap_or_default(),
InvoiceDescuentosFillRule::fill(self).unwrap_or_default(),
InvoiceFormaDePagoFillRule::fill(self).unwrap_or_default(),
InvoiceFormaDePagoTotalRule::fill(self).unwrap_or_default(),
InvoiceFormaDePagoTipoRule::fill(self).unwrap_or_default(),
InvoiceLeyendaDetraccionFillRule::fill(self).unwrap_or_default(),
InvoiceLeyendaDireccionEntregaFillRule::fill(self).unwrap_or_default(),
InvoiceLeyendaPercepcionFillRule::fill(self).unwrap_or_default(),
InvoiceTipoComprobanteFillRule::fill(self).unwrap_or_default(),
InvoiceTipoOperacionFillRule::fill(self).unwrap_or_default(),
];

changed = results.contains(&true);
Expand All @@ -141,8 +141,8 @@ where

while changed {
let results = [
NoteComprobanteAfectadoTipoFillRule::fill(self),
CreditNoteTipoFillRule::fill(self),
NoteComprobanteAfectadoTipoFillRule::fill(self).unwrap_or_default(),
CreditNoteTipoFillRule::fill(self).unwrap_or_default(),
];

changed = results.contains(&true);
Expand All @@ -159,8 +159,8 @@ where

while changed {
let results = [
NoteComprobanteAfectadoTipoFillRule::fill(self),
DebitNoteTipoFillRule::fill(self),
NoteComprobanteAfectadoTipoFillRule::fill(self).unwrap_or_default(),
DebitNoteTipoFillRule::fill(self).unwrap_or_default(),
];

changed = results.contains(&true);
Expand Down
2 changes: 1 addition & 1 deletion xbuilder/src/enricher/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
let mut changed = true;

while changed {
let results = [DetallesProcessRule::process(self)];
let results = [DetallesProcessRule::process(self).unwrap_or_default()];

changed = results.contains(&true);
}
Expand Down
38 changes: 24 additions & 14 deletions xbuilder/src/enricher/rules/phase1fill/detalle/detalles.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::{anyhow, Result};
use rust_decimal::Decimal;

use crate::enricher::bounds::detalle::DetallesGetter;
Expand All @@ -19,34 +20,43 @@ pub struct DetalleDefaults {
}

pub trait DetallesFillRule {
fn fill(&mut self) -> bool;
fn fill(&mut self) -> Result<bool>;
}

impl<T> DetallesFillRule for T
where
T: DetallesGetter + IgvTasaGetter + IcbTasaGetter + IvapTasaGetter,
{
fn fill(&mut self) -> bool {
fn fill(&mut self) -> Result<bool> {
let defaults = &DetalleDefaults {
igv_tasa: self.get_igv_tasa().expect("IGV Tasa could not be found"),
icb_tasa: self.get_icb_tasa().expect("IBC Tasa could not be found"),
ivap_tasa: self.get_ivap_tasa().expect("IVAP Tasa could not be found"),
igv_tasa: self
.get_igv_tasa()
.ok_or(anyhow!("IGV Tasa could not be found"))?,
icb_tasa: self
.get_icb_tasa()
.ok_or(anyhow!("IBC Tasa could not be found"))?,
ivap_tasa: self
.get_ivap_tasa()
.ok_or(anyhow!("IVAP Tasa could not be found"))?,
};

self.get_detalles()
let result = self
.get_detalles()
.iter_mut()
.map(|detalle| {
let results = [
DetalleICBTasaFillRule::fill(detalle, defaults),
DetalleIGVTasaFillRule::fill(detalle, defaults),
DetalleIGVTipoFillRule::fill(detalle, defaults),
DetalleISCTasaFillRule::fill(detalle, defaults),
DetalleISCTipoFillRule::fill(detalle, defaults),
DetallePrecioReferenciaTipoFillRule::fill(detalle, defaults),
DetalleUnidadMedidaFillRule::fill(detalle, defaults),
DetalleICBTasaFillRule::fill(detalle, defaults).unwrap_or_default(),
DetalleIGVTasaFillRule::fill(detalle, defaults).unwrap_or_default(),
DetalleIGVTipoFillRule::fill(detalle, defaults).unwrap_or_default(),
DetalleISCTasaFillRule::fill(detalle, defaults).unwrap_or_default(),
DetalleISCTipoFillRule::fill(detalle, defaults).unwrap_or_default(),
DetallePrecioReferenciaTipoFillRule::fill(detalle, defaults)
.unwrap_or_default(),
DetalleUnidadMedidaFillRule::fill(detalle, defaults).unwrap_or_default(),
];
results.contains(&true)
})
.any(|changed| changed)
.any(|changed| changed);
Ok(result)
}
}
10 changes: 6 additions & 4 deletions xbuilder/src/enricher/rules/phase1fill/detalle/icb_tasa.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use anyhow::Result;

use crate::enricher::bounds::detalle::icb_tasa::{DetalleIcbTasaGetter, DetalleIcbTasaSetter};
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetalleICBTasaFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetalleICBTasaFillRule for T
where
T: DetalleIcbTasaGetter + DetalleIcbTasaSetter,
{
fn fill(&mut self, defaults: &DetalleDefaults) -> bool {
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool> {
match &self.get_icb_tasa() {
Some(..) => false,
Some(..) => Ok(false),
None => {
self.set_icb_tasa(defaults.icb_tasa);
true
Ok(true)
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions xbuilder/src/enricher/rules/phase1fill/detalle/igv_tasa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use rust_decimal::Decimal;

use crate::catalogs::{Catalog7, Catalog7Group, FromCode};
Expand All @@ -6,14 +7,14 @@ use crate::enricher::bounds::detalle::igv_tipo::DetalleIgvTipoGetter;
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetalleIGVTasaFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetalleIGVTasaFillRule for T
where
T: DetalleIgvTasaGetter + DetalleIgvTasaSetter + DetalleIgvTipoGetter,
{
fn fill(&mut self, defaults: &DetalleDefaults) -> bool {
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool> {
match (self.get_igv_tasa(), *self.get_igv_tipo()) {
(None, Some(igv_tipo)) => {
if let Ok(catalog) = Catalog7::from_code(igv_tipo) {
Expand All @@ -27,12 +28,12 @@ where
},
};
self.set_igv_tasa(tasa);
true
Ok(true)
} else {
false
Ok(false)
}
}
_ => false,
_ => Ok(false),
}
}
}
10 changes: 6 additions & 4 deletions xbuilder/src/enricher/rules/phase1fill/detalle/igv_tipo.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use anyhow::Result;

use crate::catalogs::{Catalog, Catalog7};
use crate::enricher::bounds::detalle::igv_tipo::{DetalleIgvTipoGetter, DetalleIgvTipoSetter};
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetalleIGVTipoFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetalleIGVTipoFillRule for T
where
T: DetalleIgvTipoGetter + DetalleIgvTipoSetter,
{
fn fill(&mut self, _: &DetalleDefaults) -> bool {
fn fill(&mut self, _: &DetalleDefaults) -> Result<bool> {
match &self.get_igv_tipo() {
Some(..) => false,
Some(..) => Ok(false),
None => {
self.set_igv_tipo(Catalog7::GravadoOperacionOnerosa.code());
true
Ok(true)
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions xbuilder/src/enricher/rules/phase1fill/detalle/isc_tasa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use log::trace;
use rust_decimal::Decimal;

Expand All @@ -7,14 +8,14 @@ use crate::enricher::bounds::detalle::isc_tasa::{DetalleIscTasaGetter, DetalleIs
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetalleISCTasaFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetalleISCTasaFillRule for T
where
T: DetalleIscTasaGetter + DetalleIscTasaSetter + DetalleIgvTipoGetter,
{
fn fill(&mut self, _: &DetalleDefaults) -> bool {
fn fill(&mut self, _: &DetalleDefaults) -> Result<bool> {
match (&self.get_isc_tasa(), &self.get_igv_tipo()) {
(Some(isc_tasa), Some(igv_tipo)) => {
if let Ok(catalog) = Catalog7::from_code(igv_tipo) {
Expand All @@ -32,19 +33,19 @@ where
if &tasa != isc_tasa {
trace!("DetalleISCTasaEnrichRule: isc_tasa changed to {tasa}");
self.set_isc_tasa(tasa);
true
Ok(true)
} else {
false
Ok(false)
}
} else {
false
Ok(false)
}
}
(None, _) => {
self.set_isc_tasa(Decimal::ZERO);
true
Ok(true)
}
_ => false,
_ => Ok(false),
}
}
}
10 changes: 6 additions & 4 deletions xbuilder/src/enricher/rules/phase1fill/detalle/isc_tipo.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use anyhow::Result;

use crate::catalogs::{Catalog, Catalog8};
use crate::enricher::bounds::detalle::isc_tipo::{DetalleIscTipoGetter, DetalleIscTipoSetter};
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetalleISCTipoFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetalleISCTipoFillRule for T
where
T: DetalleIscTipoGetter + DetalleIscTipoSetter,
{
fn fill(&mut self, _: &DetalleDefaults) -> bool {
fn fill(&mut self, _: &DetalleDefaults) -> Result<bool> {
match &self.get_isc_tipo() {
Some(..) => false,
Some(..) => Ok(false),
None => {
self.set_isc_tipo(Catalog8::SistemaAlValor.code());
true
Ok(true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use anyhow::Result;

use crate::catalogs::{Catalog, Catalog16, Catalog7, FromCode};
use crate::enricher::bounds::detalle::igv_tipo::DetalleIgvTipoGetter;
use crate::enricher::bounds::detalle::precio_referencia_tipo::{
Expand All @@ -6,14 +8,14 @@ use crate::enricher::bounds::detalle::precio_referencia_tipo::{
use crate::enricher::rules::phase1fill::detalle::detalles::DetalleDefaults;

pub trait DetallePrecioReferenciaTipoFillRule {
fn fill(&mut self, defaults: &DetalleDefaults) -> bool;
fn fill(&mut self, defaults: &DetalleDefaults) -> Result<bool>;
}

impl<T> DetallePrecioReferenciaTipoFillRule for T
where
T: DetallePrecioReferenciaTipoGetter + DetallePrecioReferenciaTipoSetter + DetalleIgvTipoGetter,
{
fn fill(&mut self, _: &DetalleDefaults) -> bool {
fn fill(&mut self, _: &DetalleDefaults) -> Result<bool> {
match (self.get_precio_referencia_tipo(), *self.get_igv_tipo()) {
(None, Some(igv_tipo)) => {
if let Ok(catalog) = Catalog7::from_code(igv_tipo) {
Expand All @@ -23,12 +25,12 @@ where
&Catalog16::ValorReferencialUnitarioEnOperacionesNoOnerosas
};
self.set_precio_referencia_tipo(catalog16.code());
true
Ok(true)
} else {
false
Ok(false)
}
}
_ => false,
_ => Ok(false),
}
}
}
Loading

0 comments on commit 3d00890

Please sign in to comment.