30
)
31
from aram_backend.services.approval import approve_year
32
from aram_backend.services.control_context import build_control_context
33
-from test_approval_gate import _balanced
33
+from test_approval_gate import _balanced, _carry
34
from test_statement_build import _setup
35
36
D = Decimal
346
},
347
)
348
assert bad.status_code == 422
349
+
350
+
351
+class TestReclassifiedRowsAgreeWithTheEngine:
352
+ """C-06/C-07 must use the same figure `build_statements` uses.
353
+
354
+ A reclassified source row carries only `statement_balance` (already
355
+ presentation-signed) and leaves CLOSING empty. Using raw closing in the
356
+ control context would compare two different rules and invent a difference.
357
+ """
358
+
359
+ def test_display_prefers_the_pre_signed_statement_balance(self):
360
+ row = BalanceRow(1, "148348", D(0), D(0), D(0), D(0), statement_balance=D(-250))
361
+ assert row.display(D(1)) == D(-250)
362
+ assert row.display(D(-1)) == D(-250)
363
+
364
+ def test_display_signs_ordinary_closing(self):
365
+ row = BalanceRow(1, "241001", D(0), D(0), D(60), D(-60))
366
+ assert row.display(D(-1)) == D(60)
367
+
368
+ def test_context_and_engine_agree_on_a_reclassified_row(self, session):
369
+ from sqlalchemy import select
370
+
371
+ from aram_backend.models import LedgerBalance, StatementLine
372
+ from aram_backend.services.statement_build import build_statements
373
+ from test_statement_build import _map, _note, _setup
374
+
375
+ year, source = _setup(session)
376
+ _carry(session, year, source, "148348", D(0), D(0), 3)
377
+ row = session.scalar(
378
+ select(LedgerBalance).where(
379
+ LedgerBalance.year_id == year.id, LedgerBalance.account_full_code == "148348"
380
+ )
381
+ )
382
+ row.statement_balance = D(777)
383
+ note = _note(session, year, "6", "نقد", "BS", "Assets")
384
+ _map(session, year, "148348", note)
385
+ session.flush()
386
+ build_statements(session, year.id)
387
+ session.flush()
388
+
389
+ line = session.scalar(select(StatementLine).where(StatementLine.target_note_id == note.id))
390
+ ctx = build_control_context(session, year.id)
391
+ assert line.mapped_total == D(777)
392
+ assert ctx.note_totals["BS:6"] == D(777)
393
+ assert ctx.line_totals["BS:6"] == D(777)
394
+ assert check_c07(ctx.note_totals, ctx.line_totals).passed