"""Renumber a few oddly-coded accounts to cleaner positions. Idempotent — checks before each move.""" moves = [ # (current_code, target_code, expected_name_substr) ('119100', '115200', 'Due From Shareholder'), ('119900', '115900', 'Due From Associated Corporations'), ] print(">>> Easy renames (no postings)") for old, new, name_hint in moves: acc = env['account.account'].search([('code', '=', old)], limit=1) if not acc: print(f"SKIP {old}: not found") continue if name_hint.lower() not in (acc.name or '').lower(): print(f"SKIP {old}: name doesn't match expected '{name_hint}' (got '{acc.name}')") continue conflict = env['account.account'].with_context(active_test=False).search([('code', '=', new)], limit=1) if conflict: print(f"SKIP {old}->{new}: target code occupied by {conflict.name}") continue acc.code = new print(f"OK {old} -> {new}: {acc.name}") # The 511100 swap — rename legacy first, then renumber ours print(">>> 511105 -> 511100 swap") legacy = env['account.account'].with_context(active_test=False).search([('code', '=', '511100'), ('name', 'ilike', 'inside purchases')], limit=1) ours = env['account.account'].search([('code', '=', '511105'), ('name', 'ilike', 'cloud infrastructure')], limit=1) if not legacy: print("legacy 511100 not found (already moved?)") elif not ours: print("our 511105 not found (already renamed?)") else: # Rename legacy first to free the code legacy.write({'code': '511100.OLD', 'name': f"(l10n_ca LEGACY) {legacy.name}", 'active': False}) ours.code = '511100' print(f"OK legacy 511100 -> 511100.OLD ({legacy.name})") print(f"OK 511105 -> 511100 ({ours.name})") env.cr.commit() print(">>> done <<<")