test(fusion_accounting_bank_rec): migration round-trip for bootstrap step
Verifies the bank_rec_bootstrap migration step (a) creates precedents from existing partial.reconcile rows, (b) is idempotent on re-run, and (c) refreshes the MV without erroring. Three TransactionCase tests: - test_bootstrap_creates_precedents_from_existing_reconciles seeds two reconciles via the engine, wipes the auto-recorded precedents, then asserts the bootstrap produces source='backfill' precedents. - test_bootstrap_step_idempotent runs the bootstrap twice and asserts the second pass creates zero new precedents. - test_bootstrap_refreshes_mv_without_error runs the bootstrap on a clean partner and asserts no exception is raised and the result dict reports MV + pattern refresh outcomes. Implementation fixes uncovered by these tests: - precedent_backfill.backfill_precedents now pre-filters account.partial.reconcile to rows that touch a bank statement line on either side. Previously it walked every partial in the DB; on the westin-v19 dev DB that's 16k rows and the default limit=10000 missed the newest test fixtures (highest IDs). - backfill skips the periodic env.cr.commit() when running under a TestCursor, since committing inside a test breaks the rollback. Test count: 139 -> 142. Made-with: Cursor
This commit is contained in:
@@ -43,7 +43,17 @@ def backfill_precedents(env, *, company_id=None, batch_size=500, limit=10000):
|
||||
Partial = env['account.partial.reconcile'].sudo()
|
||||
Line = env['account.bank.statement.line'].sudo()
|
||||
|
||||
domain = []
|
||||
in_test_mode = env.cr.__class__.__name__ == 'TestCursor'
|
||||
|
||||
# Pre-filter to partials that touch a bank statement line on either side.
|
||||
# In a real DB we typically have 10x more invoice<->payment partials than
|
||||
# bank-rec partials; filtering here keeps the loop bounded and makes the
|
||||
# default limit reflect "real" candidates rather than every partial ever.
|
||||
domain = [
|
||||
'|',
|
||||
('debit_move_id.move_id.statement_line_id', '!=', False),
|
||||
('credit_move_id.move_id.statement_line_id', '!=', False),
|
||||
]
|
||||
if company_id:
|
||||
domain.append(('company_id', '=', company_id))
|
||||
partials = Partial.search(domain, limit=limit, order='id asc')
|
||||
@@ -91,7 +101,8 @@ def backfill_precedents(env, *, company_id=None, batch_size=500, limit=10000):
|
||||
})
|
||||
created += 1
|
||||
if created % batch_size == 0:
|
||||
env.cr.commit()
|
||||
if not in_test_mode:
|
||||
env.cr.commit()
|
||||
_logger.info(
|
||||
"Backfill progress: %d created, %d skipped",
|
||||
created, skipped)
|
||||
|
||||
Reference in New Issue
Block a user