feature/validaciones-clarion-classes-cav

This commit is contained in:
hreyes
2026-03-04 10:11:23 -07:00
parent e83205caf9
commit ccafe8d16c
7 changed files with 218 additions and 39 deletions

View File

@@ -28,6 +28,26 @@ def check_max_length(
return None
def check_min_length(
row: Dict[str, Any],
col: str,
min_len: int,
line_num: int,
msg: Optional[str] = None,
) -> Optional[Dict[str, Any]]:
"""Solo valida si hay valor; error si longitud menor que min_len."""
val = (row.get(col) or "").strip()
if not val:
return None
if len(val) < min_len:
return {
"line": line_num,
"col": col,
"msg": msg or f"Mínimo {min_len} caracteres",
}
return None
def check_int_range(
row: Dict[str, Any],
col: str,

View File

@@ -31,9 +31,10 @@ def row_to_class_data(
) -> Dict[str, Any]:
"""
Mapea una fila normalizada del CSV a un diccionario de datos para Class.
Ajusta material_key y unit_of_measure a None si no están en los conjuntos.
class_code se normaliza a mayúsculas (Clip(Upper) Clarion).
"""
class_code = _str_or_none(row_norm.get("CLASE"), 8)
raw_clase = _str_or_none(row_norm.get("CLASE"), 8)
class_code = raw_clase.upper() if raw_clase else None
desc_es = _str_or_none(row_norm.get("DESCRIPCIONE"), 500)
desc_en = _str_or_none(row_norm.get("DESCRIPCIONI"), 500)
material_key = _str_or_none(row_norm.get("CLAVEMAT"), 10)
@@ -60,3 +61,22 @@ def row_to_class_data(
"physical_review": physical_review,
"iva_exempt_fraction": iva_exempt_fraction,
}
def row_to_class_data_merge_existing(
row_norm: Dict[str, Any],
existing_data: Dict[str, Any],
valid_material_keys: Set[str],
valid_uom_codes: Set[str],
) -> Dict[str, Any]:
"""
Para modo actualizar (parcial): valores del CSV si no vacíos, sino los de la clase existente (Clarion VALIDA_PARCIAL_CLASE).
"""
data = row_to_class_data(row_norm, valid_material_keys, valid_uom_codes)
if not data["class_code"]:
return data
for key in ("description_es", "description_en", "material_key", "unit_of_measure",
"fraction", "us_fraction", "sub_key", "physical_review", "iva_exempt_fraction"):
if data.get(key) is None or (isinstance(data[key], str) and not data[key].strip()):
data[key] = existing_data.get(key)
return data