Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
fix(control): recompute trial balance totals from full account trace
davoodmehraban89 committed
Oct 31, 2026 at 08:36 UTC
7e4b6b0bef9024d5acb1668480d554e53d6875bb
1 file changed
+38
-5
backend/src/aram_backend/cross_statement_reconciliation.py
+38
-5
@@ -176,13 +176,46 @@ def _cash_flow_bridge(cash: DirectCashFlowCandidate) -> bool:
176
177
178
def _trial_balance_bridge(trial: TrialBalanceDiagnostic) -> bool:
179
- opening = _money(trial.opening_debit_net_total)
180
- debit_credit = _money(trial.movement_difference)
181
- closing = _money(trial.closing_debit_net_total)
182
- rollforward = _money(trial.opening_to_closing_difference)
179
+ if (type(trial.account_count) is not int
180
+ or trial.account_count != len(trial.accounts) or not trial.accounts):
181
+ return False
182
+ seen: set[str] = set()
183
+ openings: list[Decimal] = []
184
+ debits: list[Decimal] = []
185
+ credits: list[Decimal] = []
186
+ closings: list[Decimal] = []
187
+ for account in trial.accounts:
188
+ if not isinstance(account, TrialBalanceAccount):
189
+ return False
190
+ code = _text(account.account_code, "TRIAL_BALANCE_ACCOUNT_CODE")
191
+ if code in seen:
192
+ return False
193
+ seen.add(code)
194
+ opening = _money(account.opening)
195
+ debit = _money(account.debit)
196
+ credit = _money(account.credit)
197
+ closing = _money(account.closing)
198
+ if _sum_exact([debit, -credit]) != _money(account.debit_net_movement):
199
+ return False
200
+ openings.append(opening)
201
+ debits.append(debit)
202
+ credits.append(credit)
203
+ closings.append(closing)
204
+ opening_total = _sum_exact(openings)
205
+ debit_total = _sum_exact(debits)
206
+ credit_total = _sum_exact(credits)
207
+ closing_total = _sum_exact(closings)
208
+ movement = _sum_exact([debit_total, -credit_total])
209
+ rollforward = _sum_exact([opening_total, movement, -closing_total])
210
return (
211
trial.balanced_for_analyst_review
185
- and opening == 0 and debit_credit == 0 and closing == 0 and rollforward == 0
212
+ and opening_total == _money(trial.opening_debit_net_total)
213
+ and debit_total == _money(trial.debit_turnover_total)
214
+ and credit_total == _money(trial.credit_turnover_total)
215
+ and closing_total == _money(trial.closing_debit_net_total)
216
+ and movement == _money(trial.movement_difference) == 0
217
+ and opening_total == 0 and closing_total == 0
218
+ and rollforward == _money(trial.opening_to_closing_difference) == 0
219
)
220
221