Repository navigation
fix(fiscal): plazo de baja, motivos de nota de crédito y una sola nota total (H1/H2/H4) - #502
Merged
Merged
Conversation
H1: a Comunicacion de Baja is allowed only while both seven-day windows hold - issue date in Lima (SUNAT validation 2957) and acceptance date (art. 14.1.b) - the stricter applies and the refusal names it; also at send time and for notes voided by RA. H2: the full-reversal credit note accepts only Catalogo 09 reasons 01, 02 and 06, refused before a correlative is reserved and again at signing. H4: at most one live full credit note per original, checked under the original's row lock before reserving a number; same key stays idempotent. H3: document that the void gate relies on the not-granted attestation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Credit notes require a request_key (view 400 and service), so a note left GENERATED stays resumable by replaying its key. - A GENERATED credit note that can never be signed no longer blocks its original: a legacy reason outside 01/02/06, or a keyless one older than 30 minutes. Its number stays spent and unsent; the accountant decides. Signing such a note is refused once another full credit note lives. - Idempotency checks the request: the same key with another note type, reason or debit amount raises FiscalNoteConflict (HTTP 409). - Note creation re-checks the original's eligibility under its row lock; create_void_communication takes the same row locks and re-checks, and a void is refused while a live full credit note exists, so a note and a void on one invoice serialise and only one is born. - Comment why the CDR clock is defensive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ard weights Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A keyed credit note left GENERATED after a failed signing, whose key the client lost, blocked further credit notes and voids on the invoice. H4 now raises FullCreditNoteExists naming the live note. A pending, unsigned note answers 409 credit_note_pending_signature with its id, number, request_key and reason, so the client resumes it explicitly with that key; it is never signed inside a request that brought another key. A signed or later note keeps the 400 refusal, now with its id and number. The void refusal names the pending note the same way, and note payloads expose request_key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qué corrige (PR-1 de anulaciones, ADR #500)
Tres fallos del código que ya está en producción. Ninguno causó daño: todavía no se ha emitido ninguna nota ni ninguna baja real. Todo falla cerrado mientras las preguntas al contador sigan abiertas.
H1, plazo de la baja. Antes los 7 días se contaban desde que el sistema registró la aceptación de SUNAT. Ahora valen los dos plazos y manda el más estricto:
Las fechas se toman en hora de Lima y el mensaje de rechazo dice qué plazo aplicó. Lo mismo vale para las notas que se dan de baja.
H2, motivos de la nota de crédito. La nota siempre revierte el total, así que sólo se aceptan los motivos 01, 02 y 06. Los demás se rechazan antes de reservar el número. El 13 trae una explicación adicional: sólo aplica a ventas al crédito. Una nota antigua con otro motivo no se firma.
H4, tope. Sólo puede existir una nota de crédito viva por comprobante. El control corre dentro de la transacción, con bloqueo de la fila del original y antes de reservar el número. La misma clave sigue devolviendo la misma nota. Una nota rechazada, o dada de baja con una baja aceptada, libera el original.
H3, entrega al cliente. Queda documentado en el código. La corrección es el PR-4.
Pruebas
store.test_fiscal_annul_guards: 21 pruebas nuevas, que fallaron antes del cambio. Incluyen límites de 7 y 8 días en hora de Lima y concurrencia en PostgreSQL: dos claves distintas producen una sola nota y un solo número.tests.py: 465 pruebas en verde.Cambio de comportamiento
order_document_copyusa la misma lista de motivos. Una factura con una nota de crédito viva de motivo 02 ahora se trata como anulada y no se envía como comprobante válido.El despliegue necesita un GO propio.
🤖 Generated with Claude Code