Repository navigation
fix(tally): the reconciler re-queues a voucher missing in Tally - #632
Open
privatejoel wants to merge 1 commit into
Open
privatejoel wants to merge 1 commit into
privatejoel wants to merge 1 commit into
Conversation
applyAutoFix("missing_in_tally") wrote a tally_retry_queue row with
columns that do not exist and without the NOT NULL voucher_type,
payload_xml and payload_hash. The insert always failed, but the finding
said "re_pushed", so nothing was re-pushed.
The reconciler now queues the row through enqueueTallyVoucher: the order
is read in the finding's tenant, it must be approved, the XML comes from
buildSalesVoucherXml, and the insert error is checked. The row carries
the voucher record id, the pushed voucher number and the voucher's
company. A row that is not in the queue shows "re_push_failed" and does
not count as a fix. One automatic re-push per voucher record, because
each push creates a voucher in Tally. enqueueTallyVoucher also refuses a
cancelled order.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Summary
The drift check did not re-queue a voucher that is missing in Tally.
applyAutoFix("missing_in_tally")insrc/api/_lib/tally-reconciler.jswrote atally_retry_queuerow with three columns that do not exist (tally_voucher_record_id,attempt,reason). The row also had novoucher_type,payload_xmlorpayload_hash. These three columns are NOT NULL (016_tally_v2.sql). Thus the insert always failed. The code did not read the error and returnedre_pushed. The finding showed "re_pushed", but the queue stayed empty.This PR makes these changes:
enqueueTallyVoucher(src/api/_lib/tally-enqueue.js). This is the helper that the copilot uses. It reads the order in the finding's tenant. It refuses an order that is not approved. It builds the XML withbuildSalesVoucherXml. It setspayload_hash = order.payload_hash || approval.payloadHash. It checks the insert error.enqueueTallyVoucherhas two new optional inputs:voucherRecordIdandvoucherNo. The reconciler setsvoucher_record_idto the voucher record, so the retry drain updates that record after the push. The XML uses the voucher number that Anvil pushed before.enqueueTallyVouchernow refuses a cancelled order (ORDER_CANCELLED). After fix(so): close five sales order audit defects #631, the retry drain skips a cancelled order. Without this check, the row is queued but never pushed.re_push_failed. The run does not count it inauto_fixes_applied. The reason goes to the log.ACTION="Create", so each push can add one more voucher to the ledger. The check runs every 30 minutes. If the mirror does not show the voucher (for example, Tally gave it a different number), the old logic (if it had worked) would push the voucher again on each run. Now a later run finds the earlier row and does nothing (auto_fix_appliedstays empty). If the reconciler cannot read the queue, it does not queue (fail closed).company_idfromtally_voucher_records, so the row goes to the company that the voucher was pushed to.Deploy notes
016_tally_v2.sql.tenant_settings.tally_recon_auto_fix_enabledis true. The cron also needstally_drift_addon_enabled.pendingrows intally_retry_queuefor vouchers that the mirror does not show. Before, these rows never got written. Check the queue for each such tenant after the first cron run. Make sure thattally/syncfillstally_voucher_statefor that tenant. If not, every exported voucher is "missing" and gets one re-push.post_tally_voucheron a cancelled order now fails withORDER_CANCELLED. Before, it queued a row.Tests
src/v3-app/tally-reconciler.requeue.test.js(9 tests). Each test runs the realdriftCheck, the realenqueueTallyVoucherand the realbuildSalesVoucherXmlagainst an in-memory database. The fake database refuses atally_retry_queuerow with an unknown column or a missing NOT NULL value, as PostgREST and Postgres do. It returns only the selected columns. The tests show:re_push_failed, notre_pushed, and does not count as a fix;re_pushed.npm run check,lint,build,verify,eval:goldenandNODE_OPTIONS=--no-experimental-webstorage npx vitest runpass.Not covered
voucher_record_id. A row that the copilot queued for the same order has no voucher record id, so the reconciler does not see it.voucher_cancelled_in_tallywrites inapplyAutoFixalso do not check errors. This PR does not change them.tally_voucher_statebyvoucher_noonly. If Tally renumbers a voucher, the finding is wrong. This PR limits the damage to one re-push, but does not fix the match.🤖 Generated with Claude Code