Three odd code positions that were chosen to dodge l10n_ca collisions are
now cleaned up:
- Due From Shareholder 119100 -> 115200 (115xxx is where receivables belong)
- Due From Associated Corps 119900 -> 115900
- Cloud Infrastructure 511105 -> 511100 (legacy 'Inside Purchases'
renamed to 511100.OLD)
Applied to prod via scripts/fix_gl_codes.py (now committed).
Module XML updated: <field name='code'> values match new codes; XMLIDs
(acct_119100, acct_119900, acct_511105) preserved so existing
ir.model.data rows on prod still map to the right records.
pre_init_hook augmented with _L10N_CA_FORCE_CLEAR_CODES set so a fresh
install on a new DB also force-clears 511100 (which would otherwise be
blocked by the postings-exist guard).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
"""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 <<<")
|