diff --git a/app/db/normalizations.py b/app/db/normalizations.py index 5a69eb1..cd5315c 100644 --- a/app/db/normalizations.py +++ b/app/db/normalizations.py @@ -135,9 +135,9 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]: Normaliza campos de detalle de factura desde el registro de origen `fd`. Escalas: - quantity_value: escala 2 (cents) - - unit_value: escala 4 (cents4) + - unit_amount_value: escala 4 (cents4) - discount_percentage_value: escala 2 (10 -> 1000) - - total_value: escala 4 (cents4) + - total_amount_value: escala 4 (cents4) - iva_amount: escala 2 (cents), calculado con redondeo a 2 decimales - """ @@ -157,7 +157,7 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]: # --- cantidad y precio unitario --- quantity_value = None if cantidad is None else cents( cantidad) # escala 2 - unit_value = None if importe_unidad is None else cents4( + unit_amount_value = None if importe_unidad is None else cents4( importe_unidad) # escala 4 # --- descuento de linea % (escala 2) --- @@ -182,16 +182,17 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]: total_discount_amount_value = discount_amount_value + global_discount_amount_value # --- total de lĂ­nea (escala 4) --- - total_value = cents4(total_det) + total_amount_value = cents4(total_det) - if total_value > 0: + if total_amount_value > 0: # DEBE SER LO MISMO LO CALCULADO QUE LO QUE NOS VIENE POR BD DE FACTUGES - logger.info("total con dto linea calculado: %s - total que llega: %s", subtotal_amount_with_dto, total_value) + logger.info("total con dto linea calculado: %s - total que llega: %s", + subtotal_amount_with_dto, total_amount_value) # la base imponible sobre la que calcular impuestos es el neto menos el dto de linea y dto global base = unscale_to_decimal(taxable_amount_value, 4) - if total_value > 0: + if total_amount_value > 0: logger.info("base imponible calculada: %s - subtotal: %s - descuentodto: %s - descuentoglobal: %s", base, subtotal_amount_value, discount_amount_value, global_discount_amount_value) @@ -219,13 +220,13 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]: taxes_amount_value = iva_amount_c4 + rec_amount_c4 - total_value = taxable_amount_value + taxes_amount_value + total_amount_value = taxable_amount_value + taxes_amount_value return { 'position': int(fd.get("POSICION") or 0), 'description': rtf_a_texto_plano(str(concepto_rtf or "")), 'quantity_value': quantity_value, - 'unit_value': unit_value, + 'unit_amount_value': unit_amount_value, 'subtotal_amount_value': subtotal_amount_value, 'disc_pct': disc_pct, 'discount_percentage_value': discount_percentage_value, @@ -234,7 +235,7 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]: 'global_discount_amount_value': global_discount_amount_value, 'total_discount_amount_value': total_discount_amount_value, 'taxable_amount_value': taxable_amount_value, - 'total_value': total_value, + 'total_amount_value': total_amount_value, 'iva_code': iva_code, 'iva_percentage_value': iva_percentage_value, 'iva_amount_value': iva_amount_c4,