Skip to content

Conversation

@GISaoliva
Copy link

Causa

  • El método no contemplaba facturas de tipo "C" (Complementaria) como facturas originales.
  • En estos casos cuándo se intentaba acceder a la información inexistente ocasionando el error.

Solución

  • Se ha ampliado la condición inicial para tratar tanto facturas de tipo "N" (Normal) como "C" (Complementaria), o aquellas sin rectifying_id, como facturas originales.
  • De esta forma, se devuelve la date_invoice directamente y se evita el error de acceso al campo.

@GISaoliva GISaoliva self-assigned this Oct 3, 2025
@GISaoliva GISaoliva added the bug label Oct 3, 2025
@GISaoliva GISaoliva marked this pull request as ready for review October 21, 2025 09:20
@guilleJB guilleJB requested a review from Copilot November 3, 2025 16:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the get_fecha_operacion_rec function to handle additional rectificative types and prevent potential recursion issues. The function retrieves the operation date for rectified invoices by recursively traversing the rectifying chain.

  • Added 'C' rectificative type to the base case condition
  • Added a guard to prevent recursion when rectifying_id is falsy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +329 to 330
if invoice.rectificative_type in ('N', 'C') or not invoice.rectifying_id:
return invoice.date_invoice
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition or not invoice.rectifying_id may prevent infinite recursion, but it changes the function's behavior for rectificative types other than 'N' and 'C' when rectifying_id is missing. Consider whether types like 'R', 'A', 'B', 'RA', and 'G' (defined in the SIGN dictionary at line 11) should also be explicitly handled in this condition, or if the missing rectifying_id scenario warrants a different response (e.g., raising an exception or logging a warning) rather than silently returning invoice.date_invoice.

Suggested change
if invoice.rectificative_type in ('N', 'C') or not invoice.rectifying_id:
return invoice.date_invoice
if invoice.rectificative_type in ('N', 'C'):
return invoice.date_invoice
elif not invoice.rectifying_id:
raise ValueError(
"Invoice with rectificative_type '{}' is missing rectifying_id. Invoice ID: {}".format(
invoice.rectificative_type, getattr(invoice, 'id', 'unknown')
)
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant