fix(setup): unblock setup wizard with TT200 CoA + defer account setup #136

Merged
tant merged 2 commits from fix/wizard-tt200-compat into develop 2026-05-13 10:28:00 +07:00
Owner

See commits for detail. Fixes 3 install-wizard bugs: ERPNext sync_financial_report_templates NoneType crash, create_default_tax_template IndexError, account 4131 name >140 chars, plus ensure_payroll_accounts race condition via enqueue_after_commit.

See commits for detail. Fixes 3 install-wizard bugs: ERPNext sync_financial_report_templates NoneType crash, create_default_tax_template IndexError, account 4131 name >140 chars, plus ensure_payroll_accounts race condition via enqueue_after_commit.
ERPNext v16 setup wizard crashes when user selects vhrms's 'Vietnam - Hệ
thống tài khoản theo Thông tư 200/2014/TT-BTC' chart of accounts. Root
causes:

1. sync_financial_report_templates calls get_chart() via direct Python
   import — bypasses our override_whitelisted_methods mapping (which only
   covers API endpoints) → returns None for TT200 CoA → 'NoneType' object
   has no attribute 'get'. Patched by monkey-patching the module attribute
   at vhrms boot so any direct import resolves to vhrms's chart-aware loader.

2. create_default_tax_template assumes English account names 'Duties and
   Taxes' (Liability) / 'Tax Assets' (Asset) — TT200 uses Vietnamese names
   (333, 133) → empty query → IndexError. Patched by skipping for TT200
   CoA (admin tạo Sales/Purchase Tax Template thủ công sau setup).

3. Account 4131 name exceeded 140-char Frappe limit (175 chars w/
   account_number prefix + company abbr suffix), halting chart import at
   ~167/200+ accounts. Renamed to 75 chars.

Installation flow now works end-to-end:
  bench new-site --install-app erpnext --install-app hrms --install-app vhrms
  → user opens site → completes wizard with TT200 CoA
  → Company created + on_company_created hook seeds Lương Chính thức +
    Lương Thử việc + VAS account mappings + Vietnam leave types.
ERPNext Company.on_update → make_company_fixtures → create_default_accounts
batch-inserts CoA accounts within the same transaction as Company.after_insert.
vhrms's on_company_created hook fires before commit, so frappe.db.exists()
lookups against Account may race with the batch flush and return False even
though rows have been queued. Result: 19+ 'Không tìm thấy parent account'
errors logged + VAS account mapping skipped (642, 6428, 622, 3334, 3335,
3388…) → Salary Component → Account links missing → Salary Slip submit
raises 'Please set account in Salary Component'.

enqueue_after_commit defers ensure_payroll_accounts + assign_salary_component_accounts
to a background job that runs after the wizard transaction commits. Accounts
are fully visible by then.

_first_company_seed + _first_company_safety_net stay inline since they don't
touch Account (only Salary Structure, Leave Type, Income Tax Slab) — Salary
Structures must be available immediately after the wizard completes.
tant merged commit a911d002d4 into develop 2026-05-13 10:28:00 +07:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tant/vhrms!136
No description provided.