B-43: M3空参考号不再视为相等,单边intercompany需锁定才可计算

This commit is contained in:
腾讯WorkBuddy
2026-08-18 22:10:27 +08:00
parent df517d4a68
commit f99917321b
4 changed files with 151 additions and 14 deletions
+119
View File
@@ -677,6 +677,125 @@ class ResolutionTests(MatchingBase):
self.assertEqual("M3", candidate["rule_tier"])
class M3EvidenceTests(MatchingBase):
"""M3 requires positive reference or summary evidence; a missing reference
on either side is never treated as agreement (None == None is not equal)."""
def _alias_for_a(self) -> None:
master_data.add_alias(
self.connection, self.account_a["id"], "account", "770077007700",
actor=self.admin,
)
def test_both_references_empty_and_summaries_different_do_not_pair(self) -> None:
self._alias_for_a()
row_a = self.add_row(
self.company_a, own_account="6222000000000001",
cp_account="6222000000000002", expense="100.00", summary="货款A",
)
row_b = self.add_row(
self.company_b, own_account="6222000000000002",
cp_account="770077007700", income="100.00", summary="货款B",
)
matching.reconcile_rows(self.connection, [row_a, row_b])
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b)))
self.assertEqual([], self.eligible())
self.assertIsNone(self.connection.execute(
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
).fetchone())
def test_single_sided_reference_is_not_reference_equality(self) -> None:
self._alias_for_a()
row_a = self.add_row(
self.company_a, own_account="6222000000000001",
cp_account="6222000000000002", expense="100.00", reference="R-ONLY-A",
)
row_b = self.add_row(
self.company_b, own_account="6222000000000002",
cp_account="770077007700", income="100.00",
)
matching.reconcile_rows(self.connection, [row_a, row_b])
self.assertEqual("needs_review", matching.exposed_status(self.current(row_a)))
self.assertEqual("internal_single", matching.exposed_status(self.current(row_b)))
self.assertEqual([], self.eligible())
def test_both_references_empty_but_summary_equal_still_pairs_m3(self) -> None:
self._alias_for_a()
row_a = self.add_row(
self.company_a, own_account="6222000000000001",
cp_account="6222000000000002", expense="100.00", summary="货款",
)
row_b = self.add_row(
self.company_b, own_account="6222000000000002",
cp_account="770077007700", income="100.00", summary="货款",
)
matching.reconcile_rows(self.connection, [row_a, row_b])
self.assertEqual("matched", matching.exposed_status(self.current(row_a)))
candidate = self.connection.execute(
"SELECT rule_tier FROM transfer_match_candidates WHERE accepted = 1"
).fetchone()
self.assertEqual("M3", candidate["rule_tier"])
class EligibleViewTests(MatchingBase):
"""``eligible_intercompany_events``: single-sided intercompany events only
enter the B-44 output when locked; paired events are unaffected."""
def _insert_intercompany(self, *, pairing: str, locked: int) -> int:
now = utc_now()
with self.connection:
cursor = self.connection.execute(
"INSERT INTO canonical_transfer_events (lifecycle, created_at) VALUES ('active', ?)",
(now,),
)
event_id = int(cursor.lastrowid)
cursor = self.connection.execute(
"""
INSERT INTO transfer_match_decisions (
event_id, revision, classification, pairing, amount, currency,
effective_at, mode, rule_version, locked, created_at
) VALUES (?, 1, 'intercompany', ?, '100.00', 'CNY',
'2026-01-05T10:00:00', 'auto', 'transfer-match-v1', ?, ?)
""",
(event_id, pairing, locked, now),
)
decision_id = int(cursor.lastrowid)
for role, company_id in (("payer", self.company_a), ("payee", self.company_b)):
self.connection.execute(
"""
INSERT INTO transfer_decision_participants (
decision_id, role, company_id, bank_account_id,
resolve_method, evidence, created_at
) VALUES (?, ?, ?, NULL, 'own_exact', '{}', ?)
""",
(decision_id, role, company_id, now),
)
self.connection.execute(
"INSERT INTO current_transfer_decisions (event_id, decision_id) VALUES (?, ?)",
(event_id, decision_id),
)
return event_id
def test_unlocked_single_intercompany_is_excluded(self) -> None:
self._insert_intercompany(pairing="single", locked=0)
self.assertEqual([], self.eligible())
def test_locked_single_intercompany_is_included(self) -> None:
self._insert_intercompany(pairing="single", locked=1)
eligible = self.eligible()
self.assertEqual(1, len(eligible))
self.assertEqual("single", eligible[0]["pairing"])
self.assertEqual("100.00", eligible[0]["amount"])
def test_paired_intercompany_is_included_regardless_of_lock(self) -> None:
self._insert_intercompany(pairing="paired", locked=0)
self._insert_intercompany(pairing="paired", locked=1)
eligible = self.eligible()
self.assertEqual(2, len(eligible))
self.assertTrue(all(item["pairing"] == "paired" for item in eligible))
class ManualLinkTests(MatchingBase):
def test_manual_link_locks_pair(self) -> None:
row_a = self.add_row(