diff --git a/backend/api/v1/modules/a76/invoices/common/common_validators.py b/backend/api/v1/modules/a76/invoices/common/common_validators.py index f6e249bd..86ec7dc5 100644 --- a/backend/api/v1/modules/a76/invoices/common/common_validators.py +++ b/backend/api/v1/modules/a76/invoices/common/common_validators.py @@ -75,15 +75,15 @@ def invoice_exists_by_id( return invoice return None -def invoice_updated( +def invoice_processed( db: Session, invoice_id: str, tenant_id: int, company_id: int, errors: ErrorCollector, ) -> bool: - is_updated = ( - db.query(models.InvoiceHeader.is_updated) + is_processed = ( + db.query(models.InvoiceHeader.is_processed) .filter( models.InvoiceHeader.id == invoice_id, models.InvoiceHeader.tenant_id == tenant_id, @@ -92,12 +92,12 @@ def invoice_updated( .scalar() ) - if is_updated: + if is_processed: errors.add_error( field="invoice_number", message=f"La factura con el número '{invoice_id}' ya ha sido actualizada y no se puede modificar.", solution="Capturar otro número de Factura de Importación Temporal o Desactualizar la factura.", - code="INVOICE_UPDATED", + code="INVOICE_processed", value=invoice_id, ) return True diff --git a/backend/api/v1/modules/a76/invoices/schemas.py b/backend/api/v1/modules/a76/invoices/schemas.py index 55cbdabe..f6027833 100644 --- a/backend/api/v1/modules/a76/invoices/schemas.py +++ b/backend/api/v1/modules/a76/invoices/schemas.py @@ -56,9 +56,9 @@ class InvoiceHeaderBase(BaseModel): ) invoice_date: date = Field(..., description="Invoice date") emission_date: Optional[date] = Field(None, description="Emission date") - is_updated: bool = Field(False, description="Status") - updated_date: Optional[datetime] = Field(None, description="Update date") - who_updated: Optional[str] = Field(None, max_length=20, description="Who updated") + is_processed: bool = Field(False, description="Status") + processed_date: Optional[datetime] = Field(None, description="Update date") + who_processed: Optional[str] = Field(None, max_length=20, description="Who processed") capture_user: Optional[str] = Field(None, max_length=20, description="Capture user") traffic_light_status: Optional[str] = Field( None, max_length=50, description="Traffic light status" @@ -66,8 +66,8 @@ class InvoiceHeaderBase(BaseModel): process_log: Optional[str] = Field( None, max_length=300, description="Processing log" ) - is_updated_rec: Optional[int] = Field(None, description="Reception status") - is_updated_rep: Optional[str] = Field( + is_processed_rec: Optional[int] = Field(None, description="Reception status") + is_processed_rep: Optional[str] = Field( None, max_length=2, description="Report status" ) observation_es: Optional[str] = Field(None, description="Observations in Spanish") diff --git a/backend/api/v1/modules/a76/invoices/services.py b/backend/api/v1/modules/a76/invoices/services.py index 77f4b2fb..7480810d 100644 --- a/backend/api/v1/modules/a76/invoices/services.py +++ b/backend/api/v1/modules/a76/invoices/services.py @@ -70,7 +70,7 @@ class InvoiceService: # Apply filters if provided if filters: if filters.get("status") is not None: - query = query.filter(models.InvoiceHeader.is_updated == filters["status"]) + query = query.filter(models.InvoiceHeader.is_processed == filters["status"]) if filters.get("operation_type"): ot = filters["operation_type"] ot_val = ot.value if hasattr(ot, "value") else ot diff --git a/backend/api/v1/modules/a76/layouts_csv/facturas/tasks.py b/backend/api/v1/modules/a76/layouts_csv/facturas/tasks.py index 9d289514..d042b3e5 100644 --- a/backend/api/v1/modules/a76/layouts_csv/facturas/tasks.py +++ b/backend/api/v1/modules/a76/layouts_csv/facturas/tasks.py @@ -292,7 +292,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -453,7 +453,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, company_rfc = (company.rfc or "").strip().upper() if company else "" q_inv_expo = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -628,7 +628,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -790,7 +790,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: # Invoice lookup: imp + TEM q = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -928,7 +928,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -1185,7 +1185,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -1443,7 +1443,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, rfc_exception_egm = False q_inv_expo = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -1712,7 +1712,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -1978,7 +1978,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -2309,7 +2309,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -2647,7 +2647,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated, InvoiceHeader.is_updated_rep) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed, InvoiceHeader.is_processed_rep) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -2969,7 +2969,7 @@ def _do_scan_file(job_id: str, model_target: str, config: Optional[str] = None, with CoreSessionLocal() as session: q_inv = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -4008,7 +4008,7 @@ def _do_insert_valid_rows(job_id: str, model_target: str, job_type_override: Opt with CoreSessionLocal() as session: q = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -4275,7 +4275,7 @@ def _do_insert_valid_rows(job_id: str, model_target: str, job_type_override: Opt with CoreSessionLocal() as session: q = ( - session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_updated) + session.query(InvoiceHeader.invoice_number, InvoiceHeader.id, InvoiceHeader.is_processed) .filter( InvoiceHeader.tenant_id == tenant_id, InvoiceHeader.company_id == company_id, @@ -4913,7 +4913,7 @@ 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.is_updated = True # Mark as updated + header.is_processed = True # Mark as updated header.updated_date = datetime.utcnow() capture_user = meta.get("capture_user") or "CSV" header.who_updated = capture_user @@ -4952,7 +4952,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, - is_updated=False, + is_processed=False, system="CSV", capture_date=datetime.utcnow(), capture_user=capture_user, diff --git a/backend/api/v1/modules/a76/reports/movements/invoices/services/definitive.py b/backend/api/v1/modules/a76/reports/movements/invoices/services/definitive.py index dd710d24..fd780dbe 100644 --- a/backend/api/v1/modules/a76/reports/movements/invoices/services/definitive.py +++ b/backend/api/v1/modules/a76/reports/movements/invoices/services/definitive.py @@ -70,7 +70,7 @@ class DefinitiveImportService: estatus = row[3] # C4 - Estatus (AC o NA) # Filtrar facturas según include_cancelled - # Si include_cancelled=False, solo mostrar AC (is_updated=true) + # Si include_cancelled=False, solo mostrar AC (is_processed=true) # Si include_cancelled=True, mostrar todas (AC y NA) if not filters.include_cancelled and estatus != 'AC': continue @@ -345,7 +345,7 @@ class DefinitiveImportService: where_conditions.append(f"pd.payment_date >= TO_DATE('{filters.start_date}', 'YYYYMMDD') AND pd.payment_date <= TO_DATE('{filters.end_date}', 'YYYYMMDD')") # Note: Status filter applied at Python level after CASE WHEN in SELECT - # because is_updated doesn't directly represent AC/NA status + # because is_processed doesn't directly represent AC/NA status # Provider filter if filters.provider: diff --git a/backend/api/v1/modules/a76/reports/movements/invoices/services/export.py b/backend/api/v1/modules/a76/reports/movements/invoices/services/export.py index de65c9db..e7ac5207 100644 --- a/backend/api/v1/modules/a76/reports/movements/invoices/services/export.py +++ b/backend/api/v1/modules/a76/reports/movements/invoices/services/export.py @@ -326,8 +326,8 @@ class ExportService: Build WHERE clause for export query. IMPORTANT: Returns conditions WITHOUT the WHERE keyword (already in base query) - AC (Active) = is_updated = true - NA (Not Applicable/Deactivated) = is_updated = false + AC (Active) = is_processed = true + NA (Not Applicable/Deactivated) = is_processed = false """ conditions = [] @@ -344,11 +344,11 @@ class ExportService: # CRITICAL VALIDATION: AC/NA status filter # If include_cancelled is False (checkbox unchecked), only show AC invoices - # AC (Active) = is_updated = true - # NA (Not Applicable/Deactivated) = is_updated = false + # AC (Active) = is_processed = true + # NA (Not Applicable/Deactivated) = is_processed = false if not filters.include_cancelled: - conditions.append("ih.is_updated = true") - logger.debug("Filtering only active invoices (is_updated = true)") + conditions.append("ih.is_processed = true") + logger.debug("Filtering only active invoices (is_processed = true)") else: logger.debug("Including cancelled invoices (include_cancelled = true)") diff --git a/backend/api/v1/modules/a76/reports/movements/invoices/services/query_builders.py b/backend/api/v1/modules/a76/reports/movements/invoices/services/query_builders.py index 7b2d7fdb..b5df3bb7 100644 --- a/backend/api/v1/modules/a76/reports/movements/invoices/services/query_builders.py +++ b/backend/api/v1/modules/a76/reports/movements/invoices/services/query_builders.py @@ -16,7 +16,7 @@ class TemporaryImportQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C4, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C4, COALESCE(ped.pedimento_code, '') AS C5, COALESCE(ped.regime, '') AS C10, COALESCE(TO_CHAR(pd.entry_date, 'YYYYMMDD'), '') AS C11, @@ -39,7 +39,7 @@ class TemporaryImportQueries: COALESCE(fin.exchange_rate, 0) AS C50, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C51, COALESCE(ih.capture_user, '') AS C52, - COALESCE(ih.who_updated, '') AS C53, + COALESCE(ih.who_processed, '') AS C53, COALESCE(log.carrier_id, '') AS C54, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_num, log.license_plate), ''), '') AS C55, '' AS C56, @@ -92,7 +92,7 @@ class TemporaryImportQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C4, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C4, COALESCE(ped.pedimento_code, '') AS C5, COALESCE(fin.value_me, 0) AS C6, COALESCE(fin.value_mn, 0) AS C7, @@ -145,7 +145,7 @@ class TemporaryImportQueries: COALESCE(fin.exchange_rate, 0) AS C50, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C51, COALESCE(ih.capture_user, '') AS C52, - COALESCE(ih.who_updated, '') AS C53, + COALESCE(ih.who_processed, '') AS C53, COALESCE(log.carrier_id, '') AS C54, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_num, log.license_plate), ''), '') AS C55, '' AS C56, @@ -230,7 +230,7 @@ class DefinitiveImportQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C4, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C4, COALESCE(ped.pedimento_code, '') AS C5, COALESCE(ped.regime, '') AS C10, COALESCE(TO_CHAR(pd.entry_date, 'YYYYMMDD'), '') AS C11, @@ -254,7 +254,7 @@ class DefinitiveImportQueries: COALESCE(fin.exchange_rate, 0) AS C51, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C52, COALESCE(ih.capture_user, '') AS C53, - COALESCE(ih.who_updated, '') AS C54, + COALESCE(ih.who_processed, '') AS C54, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C56, '' AS C57, '' AS C58, @@ -299,7 +299,7 @@ class DefinitiveImportQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C4, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C4, COALESCE(ped.pedimento_code, '') AS C5, COALESCE(fin.value_me, 0) AS C6, COALESCE(fin.value_mn, 0) AS C7, @@ -352,7 +352,7 @@ class DefinitiveImportQueries: COALESCE(fin.exchange_rate, 0) AS C50, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C51, COALESCE(ih.capture_user, '') AS C52, - COALESCE(ih.who_updated, '') AS C53, + COALESCE(ih.who_processed, '') AS C53, COALESCE(log.carrier_id, '') AS C54, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C55, '' AS C56, @@ -446,7 +446,7 @@ class RepairImportQueries: ih.invoice_number AS C2, COALESCE(ped.pedimento_number, '') AS C3, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C4, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C5, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C5, COALESCE(ped.pedimento_code, '') AS C6, COALESCE(ped.regime, '') AS C7, COALESCE(TO_CHAR(pd.payment_date, 'YYYYMMDD'), '') AS C9, @@ -463,7 +463,7 @@ class RepairImportQueries: COALESCE(fin.exchange_rate, 0) AS C40, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C41, COALESCE(ih.capture_user, '') AS C42, - COALESCE(ih.who_updated, '') AS C43, + COALESCE(ih.who_processed, '') AS C43, COALESCE(log.carrier_id, '') AS C44, COALESCE(log.transport_num, '') AS C45, COALESCE(ped.pedimento_code, '') AS C47, @@ -527,7 +527,7 @@ class RepairImportQueries: ih.invoice_number, COALESCE(ped.pedimento_number, ''), TO_CHAR(ih.invoice_date, 'YYYYMMDD'), - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END, COALESCE(ped.pedimento_code, ''), COALESCE(ped.regime, ''), COALESCE(TO_CHAR(pd.entry_date, 'YYYYMMDD'), ''), @@ -569,7 +569,7 @@ class RepairImportQueries: COALESCE(fin.exchange_rate, 0), COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), ''), COALESCE(ih.capture_user, ''), - COALESCE(ih.who_updated, ''), + COALESCE(ih.who_processed, ''), COALESCE(log.carrier_id, ''), COALESCE(log.transport_num, ''), '', @@ -664,7 +664,7 @@ class ExportQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C6, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C6, COALESCE(ped.pedimento_code, '') AS C7, COALESCE(ped.regime, '') AS C8, COALESCE(TO_CHAR(pd.end_date, 'YYYYMMDD'), TO_CHAR(pd.payment_date, 'YYYYMMDD'), '') AS C10, @@ -682,7 +682,7 @@ class ExportQueries: COALESCE(fin.exchange_rate, 0) AS C48, COALESCE(TO_CHAR(ih.emission_date, 'YYYYMMDD'), '') AS C49, COALESCE(ih.capture_user, '') AS C50, - COALESCE(ih.who_updated, '') AS C51, + COALESCE(ih.who_processed, '') AS C51, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C53, COALESCE(fin.value_me, 0) AS total_me, COALESCE(fin.value_mn, 0) AS total_mn, @@ -775,7 +775,7 @@ class ExportQueries: fin.exchange_rate AS C48, -- [47] ih.emission_date AS C49, -- [48] ih.capture_user AS C50, -- [49] - ih.who_updated AS C51, -- [50] + ih.who_processed AS C51, -- [50] '' AS C52, -- [51] COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C53, -- [52] NumCaja '' AS C54, -- [53] Pedimento18 @@ -874,7 +874,7 @@ class ExportRepairQueries: ih.invoice_number AS C1, COALESCE(ped.pedimento_number, '') AS C2, TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C6, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C6, COALESCE(ped.pedimento_code, '') AS C7, COALESCE(ped.regime, '') AS C8, COALESCE(TO_CHAR(pd.payment_date, 'YYYYMMDD'), '') AS C11, @@ -892,7 +892,7 @@ class ExportRepairQueries: COALESCE(fin.exchange_rate, 0) AS C48, COALESCE(TO_CHAR(ih.invoice_date, 'YYYYMMDD'), '') AS C49, COALESCE(ih.capture_user, '') AS C50, - COALESCE(ih.who_updated, '') AS C51, + COALESCE(ih.who_processed, '') AS C51, COALESCE(log.carrier_id, '') AS C52, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C53, COALESCE(fin.value_me, 0) AS total_me, @@ -943,7 +943,7 @@ class ExportRepairQueries: TO_CHAR(ih.invoice_date, 'YYYYMMDD') AS C3, COALESCE(fin.value_me, 0) AS C4, COALESCE(fin.value_mn, 0) AS C5, - CASE WHEN ih.is_updated THEN 'AC' ELSE 'NA' END AS C6, + CASE WHEN ih.is_processed THEN 'AC' ELSE 'NA' END AS C6, COALESCE(ped.pedimento_code, '') AS C7, COALESCE(ped.regime, '') AS C8, COALESCE(TO_CHAR(pd.entry_date, 'YYYYMMDD'), '') AS C9, @@ -992,7 +992,7 @@ class ExportRepairQueries: COALESCE(fin.exchange_rate, 0) AS C48, COALESCE(TO_CHAR(ih.invoice_date, 'YYYYMMDD'), '') AS C49, COALESCE(ih.capture_user, '') AS C50, - COALESCE(ih.who_updated, '') AS C51, + COALESCE(ih.who_processed, '') AS C51, COALESCE(log.carrier_id, '') AS C52, COALESCE(NULLIF(CONCAT_WS(' ', log.transport_id, log.transport_num), ''), '') AS C53, '' AS C54, diff --git a/backend/api/v1/modules/a76/reports/movements/invoices/services/repair.py b/backend/api/v1/modules/a76/reports/movements/invoices/services/repair.py index bf89f124..13d50c43 100644 --- a/backend/api/v1/modules/a76/reports/movements/invoices/services/repair.py +++ b/backend/api/v1/modules/a76/reports/movements/invoices/services/repair.py @@ -74,7 +74,7 @@ class RepairImportService: estatus = row[3] # C5 - Estatus (AC o NA) # Filtrar facturas según include_cancelled - # Si include_cancelled=False, solo mostrar AC (is_updated=true) + # Si include_cancelled=False, solo mostrar AC (is_processed=true) # Si include_cancelled=True, mostrar todas (AC y NA) if not filters.include_cancelled and estatus != 'AC': continue @@ -355,7 +355,7 @@ class RepairImportService: where_conditions.append(f"pd.payment_date >= TO_DATE('{filters.start_date}', 'YYYYMMDD') AND pd.payment_date <= TO_DATE('{filters.end_date}', 'YYYYMMDD')") # Note: Status filter applied at Python level after CASE WHEN in SELECT - # because is_updated doesn't directly represent AC/NA status + # because is_processed doesn't directly represent AC/NA status # Provider filter if filters.provider: diff --git a/backend/api/v1/modules/a76/reports/movements/invoices/services/temporary.py b/backend/api/v1/modules/a76/reports/movements/invoices/services/temporary.py index 1e3faa70..ad55baf3 100644 --- a/backend/api/v1/modules/a76/reports/movements/invoices/services/temporary.py +++ b/backend/api/v1/modules/a76/reports/movements/invoices/services/temporary.py @@ -70,7 +70,7 @@ class TemporaryImportService: estatus = row[3] # C4 - Estatus (AC o NA) # Filtrar facturas según include_cancelled - # Si include_cancelled=False, solo mostrar AC (is_updated=true) + # Si include_cancelled=False, solo mostrar AC (is_processed=true) # Si include_cancelled=True, mostrar todas (AC y NA) if not filters.include_cancelled and estatus != 'AC': continue @@ -421,7 +421,7 @@ class TemporaryImportService: where_conditions.append(f"pd.payment_date >= TO_DATE('{filters.start_date}', 'YYYYMMDD') AND pd.payment_date <= TO_DATE('{filters.end_date}', 'YYYYMMDD')") # Note: Status filter applied at Python level after CASE WHEN in SELECT - # because is_updated doesn't directly represent AC/NA status + # because is_processed doesn't directly represent AC/NA status # Provider filter if filters.provider: diff --git a/frontend/src/lib/api/dashboard/a76/invoices.ts b/frontend/src/lib/api/dashboard/a76/invoices.ts index 039226ba..16eb1434 100644 --- a/frontend/src/lib/api/dashboard/a76/invoices.ts +++ b/frontend/src/lib/api/dashboard/a76/invoices.ts @@ -208,14 +208,14 @@ export interface Invoice { invoice_date?: string | null; capture_date: string; emission_date?: string | null; - is_updated?: boolean | null; - updated_date?: string | null; - who_updated?: string | null; + is_processed?: boolean | null; + processed_date?: string | null; + who_processed?: string | null; capture_user?: string | null; traffic_light_status?: string | null; process_log?: string | null; - is_updated_rec?: number | null; - is_updated_rep?: string | null; + is_processed_rec?: number | null; + is_processed_rep?: string | null; observation_es?: string | null; observation_en?: string | null; comments_status?: string | null; @@ -238,7 +238,7 @@ export interface Invoice { enajenation_goods?: boolean | null; compliance_mx?: InvoiceComplianceMx | null; financials?: InvoiceFinancials | null; - logistics?: InvoiceLogistics; + logistics?: InvoiceLogistics[]; details?: InvoiceSalesDetails[]; collections?: InvoiceCollections[]; // Client-side only properties @@ -266,14 +266,14 @@ export interface CreateInvoiceData { proforma_number?: string | null; invoice_date?: string | null; emission_date?: string | null; - is_updated?: boolean | null; - updated_date?: string | null; - who_updated?: string | null; + is_processed?: boolean | null; + processed_date?: string | null; + who_processed?: string | null; capture_user?: string | null; traffic_light_status?: string | null; process_log?: string | null; - is_updated_rec?: number | null; - is_updated_rep?: string | null; + is_processed_rec?: number | null; + is_processed_rep?: string | null; observation_es?: string | null; observation_en?: string | null; comments_status?: string | null; @@ -319,7 +319,7 @@ export interface UpdateInvoiceData { cfdi_uuid?: string | null; path_pdf?: string | null; path_xml?: string | null; - is_updated?: boolean | null; + is_processed?: boolean | null; compliance_mx?: Partial | null; financials?: Partial | null; logistics?: Partial[] | null; diff --git a/frontend/src/lib/components/dashboard/invoices/columns.ts b/frontend/src/lib/components/dashboard/invoices/columns.ts index 95d3e7e5..aa24340e 100644 --- a/frontend/src/lib/components/dashboard/invoices/columns.ts +++ b/frontend/src/lib/components/dashboard/invoices/columns.ts @@ -271,7 +271,7 @@ export function createColumns( accessorKey: "logistics.weight_type", header: "Tipo Peso", cell: ({ row }) => { - const weightType = row.original.logistics?.weight_type; + const weightType = row.original.logistics?.[0]?.weight_type; const weightSnippet = createRawSnippet<[{ type?: string | null }]>((getType) => { const { type } = getType(); @@ -284,15 +284,15 @@ export function createColumns( } }, { - accessorKey: "is_updated", + accessorKey: "is_processed", header: "Actualizado", cell: ({ row }) => { - const isUpdated = row.original.is_updated; + const isprocessed = row.original.is_processed; - const updatedSnippet = createRawSnippet<[{ isUpdated?: boolean | null }]>((getUpdated) => { - const { isUpdated } = getUpdated(); - const colorClass = isUpdated ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'; - const label = isUpdated ? 'Sí' : 'No'; + const processedSnippet = createRawSnippet<[{ isprocessed?: boolean | null }]>((getprocessed) => { + const { isprocessed } = getprocessed(); + const colorClass = isprocessed ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'; + const label = isprocessed ? 'Sí' : 'No'; return { render: () => ` @@ -300,7 +300,7 @@ export function createColumns( ` }; }); - return renderSnippet(updatedSnippet, { isUpdated }); + return renderSnippet(processedSnippet, { isprocessed }); } }, { diff --git a/frontend/src/lib/components/dashboard/invoices/details-dialog.svelte b/frontend/src/lib/components/dashboard/invoices/details-dialog.svelte index bf6bb7f7..7d536622 100644 --- a/frontend/src/lib/components/dashboard/invoices/details-dialog.svelte +++ b/frontend/src/lib/components/dashboard/invoices/details-dialog.svelte @@ -121,7 +121,7 @@

Actualizado

-

{invoice.is_updated ? 'Sí' : 'No'}

+

{invoice.is_processed ? 'Sí' : 'No'}

@@ -151,8 +151,8 @@
-

Código de Pedimento

-

{invoice.compliance_mx.pedimento_code || '-'}

+

Código de Pedimento

+

{invoice.compliance_mx.pedimento?.pedimento_code || '-'}

@@ -265,8 +265,8 @@
-

Factor IVA

-

{formatNumber(invoice.financials.iva_factor)}

+

Factor IVA

+

{invoice.financials.iva_factor || '-'}

diff --git a/frontend/src/routes/dashboard/invoices/+page.svelte b/frontend/src/routes/dashboard/invoices/+page.svelte index b5079dca..ebb12d01 100644 --- a/frontend/src/routes/dashboard/invoices/+page.svelte +++ b/frontend/src/routes/dashboard/invoices/+page.svelte @@ -679,7 +679,7 @@ const companyId = companyStore.activeCompany.id; const response = await invoicesApi.update(selectedInvoice.id, companyId, { id: selectedInvoice.id, - is_updated: status + is_processed: status }); if (response.error) { diff --git a/scripts/init_first_time.sh b/scripts/init_first_time.sh index e4fb6bd9..1302193f 100755 --- a/scripts/init_first_time.sh +++ b/scripts/init_first_time.sh @@ -236,7 +236,7 @@ seed_invoices() { # 1. invoice_header — una fila por factura con fecha real en cada mes # ------------------------------------------------------------------------- exec_pg_sql "INSERT INTO a76.invoice_header - (tenant_id, company_id, system, operation_type, invoice_type, invoice_number, invoice_date, is_updated, created_at, updated_at) + (tenant_id, company_id, system, operation_type, invoice_type, invoice_number, invoice_date, is_processed, created_at, updated_at) VALUES -- Abril 2025 (4 facturas) (${TENANT_ID}, ${COMPANY_ID}, 'fixed_asset', 'imp', 'DEF', 'SEED-2025-04-001', '2025-04-03', false, '2025-04-03 08:00:00', '2025-04-03 08:00:00'),