Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
test(mapping): ensure duplicate target blocks only that statement and never passes review
davoodmehraban89 committed
Oct 31, 2026 at 09:32 UTC
6445d32f3a5309cbf609010e46befa141bdbc406
1 file changed
+60
backend/tests/test_reconciliation_review.py
+60
@@ -284,3 +284,63 @@ def test_preview_integrity_rejects_mapping_trace_amount_tampering():
284
with pytest.raises(CoverageError) as exc:
285
_validated_preview(data, altered)
286
assert exc.value.code == "MAPPING_TRACE_SOURCE_MISMATCH"
287
+
288
+
289
+def test_ambiguous_bs_mapping_does_not_hide_valid_eq_mapping_or_pass_review():
290
+ source = workbook()
291
+ book = load_workbook(BytesIO(source))
292
+ book["Notes"].append([
293
+ "001", 1404, "BS", "Assets", "N02", "Second BS note", "", "",
294
+ ])
295
+ book["Notes"].append([
296
+ "001", 1404, "EQ", "Equity", "E01", "Equity note", "", "",
297
+ ])
298
+ headers = SHEET_HEADERS["Mapping"]
299
+ base = {
300
+ header: book["Mapping"].cell(2, index + 1).value
301
+ for index, header in enumerate(headers)
302
+ }
303
+ second_bs = dict(base)
304
+ second_bs.update({"mapping_id": "M-BS-SECOND", "note_number": "N02"})
305
+ book["Mapping"].append([second_bs.get(header) for header in headers])
306
+ equity_mapping = dict(base)
307
+ equity_mapping.update({
308
+ "mapping_id": "M-EQ-001", "target_statement": "EQ",
309
+ "statement_section": "Equity", "note_number": "E01",
310
+ })
311
+ book["Mapping"].append([equity_mapping.get(header) for header in headers])
312
+ output = BytesIO()
313
+ book.save(output)
314
+ book.close()
315
+ data = output.getvalue()
316
+
317
+ preview = preview_mapping_coverage(data, company_code="001", fiscal_year=1404)
318
+ account = next(row for row in preview.accounts if row.account_code == "0010")
319
+ assert account.included
320
+ assert account.mapping_count == 3
321
+ assert account.mapping_id is None
322
+ assert any(
323
+ item.included and item.target_statement == "EQ"
324
+ and item.account_code == "0010" for item in preview.mappings
325
+ )
326
+ assert not any(
327
+ item.included and item.target_statement == "BS"
328
+ and item.account_code == "0010" for item in preview.mappings
329
+ )
330
+ assert any(
331
+ item.code == "AMBIGUOUS_ACCOUNT_MAPPING"
332
+ and item.account_code == "0010" for item in preview.exceptions
333
+ )
334
+
335
+ reviewed = reconcile_workbook_for_review(
336
+ data, company_code="001", fiscal_year=1404,
337
+ references=[
338
+ ref("15.75", note="N01"),
339
+ ref("110.25", note="E01", statement="EQ", section="Equity"),
340
+ ],
341
+ )
342
+ assert not reviewed.matched_for_analyst_review
343
+ assert any(
344
+ finding.code == "BLOCKED_ACCOUNT_AMBIGUOUS_ACCOUNT_MAPPING"
345
+ and finding.account_code == "0010" for finding in reviewed.findings
346
+ )