Use two-sided internal transfers and keep the provider settlement in its own journal.
If I review team budgets alongside a provider statement from 2Captcha, I want a clean answer when somebody moves an approved internal allowance between teams. Both team allowances change. The provider total stays where it was. A straightforward test can preserve both facts and show exactly what would go wrong if a reporting query added the debit as new expense.
Prepared with AI assistance. I ran the Python example locally with fictional records. It tests the stated assumptions for a downstream workflow.
Start with the incident I would want to explain
A fictional team called Search starts with 900 cents of testing allowance. Catalog has 300. A reviewer approves a transfer of 250 cents from Search to Catalog. Later, the reconciler imports a 130-cent provider settlement belonging to Catalog. The team dashboard now shows Search with 650 available and Catalog with 420. The provider report shows 130 posted cents. If those two views seem impossible to reconcile, draw the line separating the two journals.
This case is about internal budget accounting. The example uses invented cents and team names and creates no service-side transaction. A transfer can have a reference such as T-41 and a charge can have a receipt such as P-17. Their presence in the same reporting period provides no evidence that one caused the other. I would require a separate reference if a finance reviewer genuinely wants to associate them.
Write an input contract that treats the journals separately
Keep whole minor units in a declared currency for both positions and movements. A transfer has an identifier, an originating team, a receiving team and an amount. Validate the amount before reading balances. I would also check that both teams exist, the source and destination differ, and the source has enough available allowance. A replay with the same identifier and exactly the same record is a successful repeat observation. A changed record with that identifier is disputed evidence and should fail visibly.
For this fixture the position of a team is its opening allowance plus net internal movement minus posted charges. A company total needs a different view of the inputs. All approved transfers net to zero across this company. The sum of the team positions falls by the posted charges. This is the check I would put below the report. It catches a missing side of a transfer even when a single team looks plausible.
A charge belongs in its own collection indexed by a settlement reference. Import its provider event once and compute its impact on the eligible team. How you decide the owner is outside the transfer rule. Too many ledger designs put one flag on a row to mean both approved for this team and charged by the provider. If that flag changes mid-month, the original decision can disappear from the evidence. Give the two permissions, times and actors their own fields.
Run two teams through the journal
The code groups one transfer behind a single logical operation. I keep source and destination updates close together and reuse the transfer record when a file is imported again. The two assertions after replay are intentionally about different categories of evidence.
from dataclasses import dataclass
@dataclass(frozen=True)
class Transfer:
source: str
dest: str
cents: int
class Ledger:
def __init__(self, balances):
self.available = dict(balances)
self.opening = sum(balances.values())
self.transfers = {}
self.posted = {}
def transfer(self, reference, entry):
if reference in self.transfers:
if self.transfers[reference] != entry:
raise ValueError("conflicting transfer reference")
return False
if (
entry.source == entry.dest
or type(entry.cents) is not int
or entry.cents <= 0
or entry.source not in self.available
or entry.dest not in self.available
or self.available[entry.source] < entry.cents
):
raise ValueError("invalid transfer")
self.available[entry.source] -= entry.cents
self.available[entry.dest] += entry.cents
self.transfers[reference] = entry
return True
def post_charge(self, reference, team, cents):
if reference in self.posted:
if self.posted[reference] != (team, cents):
raise ValueError("conflicting settlement")
return False
if team not in self.available or type(cents) is not int or cents <= 0:
raise ValueError("invalid settlement")
self.posted[reference] = (team, cents)
self.available[team] -= cents
return True
ledger = Ledger({"Search": 900, "Catalog": 300})
transfer = Transfer("Search", "Catalog", 250)
assert ledger.transfer("T-41", transfer)
assert not ledger.transfer("T-41", transfer)
assert sum(ledger.available.values()) == ledger.opening
for ref, item in (("T-41", Transfer("Search", "Catalog", 251)),
("T-42", Transfer("Search", "Catalog", 651))):
try:
ledger.transfer(ref, item)
except ValueError:
assert ledger.available == {"Search": 650, "Catalog": 550}
else:
raise AssertionError("bad transfer was accepted")
assert ledger.post_charge("P-17", "Catalog", 130)
assert not ledger.post_charge("P-17", "Catalog", 130)
spend = sum(cents for _, cents in ledger.posted.values())
assert sum(ledger.available.values()) + spend == ledger.opening
print(f"Search {ledger.available['Search']}; Catalog {ledger.available['Catalog']}; posted {spend}")
A local execution printed the following result.
Search 650; Catalog 420; posted 130
The failed transfer happens before its ID can appear among accepted records. That is useful when an operator wants to fix a data entry and try again. An accepted reference can only be replayed with the same tuple. The final values show both teams and the settled charge, which gives a reviewer the numbers needed to add up the movement by hand.
This demonstration keeps the collections in memory so that the journal can be read quickly. A database implementation would write both affected positions and the unique reference in a single transaction. Concurrent approvals must use a transaction isolation strategy that guarantees the available amount at the moment of commit, such as a serializable transaction with a logged retry when it conflicts.
Read the two-sided movement before checking the combined report
Open a simple register with Search on one row and Catalog on another. Label the internal movement column as the signed change to that team's allowance. Display -250 for Search and +250 for Catalog under T-41. On the import that brings in P-17, enter 130 in a separate posted expense column for Catalog. An exported single line for the whole group should show zero movement and 130 expense. The earlier report that put one transfer leg in expense would show 380, which is an exact symptom the test can call out rather than a general warning about accounting.
Give a reversal its own authorized reference
A team might approve T-41 on Tuesday and reverse it on Wednesday. The reversal is a new movement that references T-41 and points in the opposite direction. A replay of Tuesday's file still exists in the source evidence and should remain idempotent. I would record any limit on reversal explicitly, for example if Catalog has already used most of its allowance. The report can preserve the Tuesday positions as known then and present the Wednesday adjustment in the period it belongs to. That is much easier to explain than an edit silently replacing what happened earlier.
Compare with a budget overrun on the provider side
A posted settlement is evidence that spend occurred even if the internal team allowance was insufficient. The fixture accepts a valid provider settlement that overruns a team and could show a negative position. This is deliberately different from approving a new transfer with insufficient available allowance. As an operator I want the overrun visible so somebody can review it. I would hold a settlement with an unknown team in a separate review queue, retaining its provider reference and amount in the company view until ownership is established.
Keep a currency mismatch outside the fixture's scope
A cents column describes minor units and needs its currency. If Search uses one currency and Catalog reports another, moving the same integer across both creates a fake group invariant. Group currencies separately and write down the separate conversion or exchange adjustment that applies under the organization's policy. The useful minimum test there is a pair of equal integers in two currencies. A validation report should refuse to present the pair as an offsetting total even when the numbers happen to cancel.
Instrument the decisions an operator can act on
I would expose accepted, replayed and conflicting transfer counts separately. A repeat import can produce a healthy spike in replayed rows. A conflicting reference needs a private review because somebody may have reused an identifier or changed data after approval. Include the reference, a safe reason and the importing file's revision. Put sensitive statement details behind the normal account access controls. A daily count should never require someone to export the raw provider evidence to a shared chat.
The budget view can show approved opening allowance, internal movement, posted charge and available allowance. Add the reconciliation delta for company totals and verify that it remains zero for a clean export. When the delta is nonzero, the fastest diagnosis is to scan the set of transfer references for a missing side and compare the set of settlement references with the retained inputs. That is more actionable than resumming a thousand balances.
A late correction calls for an effective period, a processing timestamp and a pinned version of the report. State whether a change belongs to a prior period or the current one. If a budgeting committee sees the same named table with different numbers on different days, it should be able to identify the approved correction that makes the second publication valid.
Decide what belongs in the pull request
I would include the clean two-team example, a replay and a rejected conflict in the change description. Separately add a case with a contradictory movement direction and a currency mismatch. The reviewer can predict the opening and closing positions, verify the net group movement, and identify which journal contributes the posted amount. If they need to read a hidden query to determine which table holds the truth, improve the report labels before adding a more complex test.
The keyboard-friendly handoff is a small CSV of the fictional events and a table of expected cents. A finance analyst can recalculate the result with a spreadsheet. A developer can bundle the loop above with tests that roll back after intentionally blocking the second line. Both should come back with a single posting and a conserved group allowance before spend.
Build a review folder both teams can replay
I would make the first review from a fictional transfer register and a separately dated settlement export. Have one person perform the review from an untouched export of the fixture and have another person run the example. Compare their explanations of opening-to-closing allowance movement before comparing any rounded number or success badge. An agreement on the final display can hide a disagreement about which input rows belong in the reported population. If the two explanations differ, trace the first decision in the transfer and settlement classification rules that separates them. That makes a repeatable check out of an argument about which output looks familiar.
Save an example where the difference is small enough to escape casual review, then put its input next to a fictional transfer register and a separately dated settlement export. Separate the evidence the operator was able to obtain from an assumption made by the reporting code. The reviewer should be able to identify what a repeated transfer ID with a changed amount looks like in the input before learning how the program reports it. For the failed example, write down which output would be misleading and which evidence would allow a later review to resolve the case.
The release evidence I would ask the team budget owner to keep is the input reference, the effective rule and the observed opening-to-closing allowance movement. A short explanation alongside those fields helps when a later change affects only one reader or time period. Append the evidence to the release note for the small change that produced it. That gives future operators a place to ask whether the output they see today was already possible in the previous release. Keep a stable label for the expected failure case even if the note, export layout or display title changes.
Finally, replay the same inputs in a clean workspace. Re-create the derived evidence before looking at a copy from the earlier run. If the second workspace cannot reproduce opening-to-closing allowance movement, record which input, time boundary or method version was missing. A third reviewer should be able to distinguish a discrepancy in a fictional transfer register and a separately dated settlement export from a discrepancy in the transfer and settlement classification rules. That check is most valuable when the normal system continues running and presents a plausible value after one dependency changes.
Try a single transfer in your own cost review
Pick one internal movement that both teams can explain, pair it with a known settled row from 2Captcha, and reproduce the calculation in a disposable report. Require reviewers to answer where the money moved and what was actually charged. Once they can answer both from the same evidence set, the rule is a reasonable candidate for the regular budget close.
Further reading
Decode the Sign of a 2Captcha Statement Row Before Reconciling It Use that sign convention on the provider journal used for settlement.
Attribute a 2Captcha Expense to the Team That Owned the Job at the Time Use ownership at the time of the job when assigning the settled charge.
Reject Nonfinite 2Captcha Balance Values Before Storing Them Validate the numeric input before it enters any journal.
Top comments (0)