Merge pull request 'feature/csv-pruebas' (#229) from feature/csv-pruebas into development

Reviewed-on: ADUANASOFT/anexo76#229
This commit is contained in:
2026-03-18 22:13:00 +00:00
2 changed files with 11 additions and 7 deletions

View File

@@ -44,15 +44,15 @@ def scan_file(self, job_id: str, model_target: str, config: str = None):
if model_target == "invoice_header":
from api.v1.modules.a76.layouts_csv.facturas.tasks import _do_scan_file
return _do_scan_file(job_id, "invoice_header", config, job_type_override="exp")
return _do_scan_file(self, job_id, "invoice_header", config, job_type_override="exp")
if model_target == "invoice_details":
from api.v1.modules.a76.layouts_csv.facturas.tasks import _do_scan_file
return _do_scan_file(job_id, "invoice_details", config, job_type_override="exp")
return _do_scan_file(self, job_id, "invoice_details", config, job_type_override="exp")
if model_target == "invoice_series":
from api.v1.modules.a76.layouts_csv.facturas.tasks import _do_scan_file
return _do_scan_file(job_id, "invoice_series", config, job_type_override="exp")
return _do_scan_file(self, job_id, "invoice_series", config, job_type_override="exp")
# Fallback (e.g. unknown model_target)
file_path = _ensure_file(job_id)

View File

@@ -185,10 +185,10 @@ def _validate_customs_broker_ref(
@celery_app.task(bind=True)
def scan_file(self, job_id: str, model_target: str, config: str = None, job_type_override: Optional[str] = None):
"""Pass 1: Read CSV, Validate types, Write Errors to JSONL. Delegates to _do_scan_file."""
return _do_scan_file(job_id, model_target, config, job_type_override)
return _do_scan_file(self, job_id, model_target, config, job_type_override)
def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, job_type_override: Optional[str] = None) -> Dict[str, Any]:
def _do_scan_file(self, job_id: str, model_target: str, config: Optional[str] = None, job_type_override: Optional[str] = None) -> Dict[str, Any]:
"""Pass 1 body: load file/meta from storage, run validations, store error lines. Uses effective_job_type for storage."""
effective_job_type = job_type_override if job_type_override is not None else JOB_TYPE
log_prefix = "Exportación import" if effective_job_type else "Invoices import"
@@ -4487,6 +4487,7 @@ def _do_insert_valid_rows(job_id: str, model_target: str, job_type_override: Opt
InvoiceFinancials,
InvoiceLogistics,
InvoiceSalesDetails,
InvoiceStatus,
OperationType,
TransportType,
WeightUnit,
@@ -4925,7 +4926,10 @@ def _do_insert_valid_rows(job_id: str, model_target: str, job_type_override: Opt
header = existing_header
header.invoice_date = invoice_date
header.operation_type = op_type_value
header.status = True # Mark as updated
# CSV import only captures data; "processed" is set by the manual/import processing flow.
# Legacy CSV imports may have persisted booleans ('True'/'False') into status.
if header.status not in (InvoiceStatus.PENDING, InvoiceStatus.PROCESSED, InvoiceStatus.REVERSED):
header.status = InvoiceStatus.PENDING
header.updated_date = datetime.utcnow()
capture_user = meta.get("capture_user") or "CSV"
header.who_processed = capture_user
@@ -4964,7 +4968,7 @@ def _do_insert_valid_rows(job_id: str, model_target: str, job_type_override: Opt
invoice_number=invoice_number,
invoice_date=invoice_date,
operation_type=op_type_value,
status=False,
status=InvoiceStatus.PENDING,
system="CSV",
capture_date=datetime.utcnow(),
capture_user=capture_user,