Debian Codegraph @

addons/l10n_vn/migrations/14.0.2.0.1/post-migration.py

raw
1 # -*- coding: utf-8 -*-
2 from odoo import api, SUPERUSER_ID
3
4 FIXED_ACCOUNTS_MAP = {
5 '5221': '5211',
6 '5222': '5212',
7 '5223': '5213'
8 }
9
10
11 def _fix_revenue_deduction_accounts_code(env):
12 vn_template = env.ref('l10n_vn.vn_template')
13 for company in env['res.company'].with_context(active_test=False).search([('chart_template_id', '=', vn_template.id)]):
14 for incorrect_code, correct_code in FIXED_ACCOUNTS_MAP.items():
15 account = env['account.account'].search([('code', '=', incorrect_code), ('company_id', '=', company.id)])
16 if account:
17 account.write({'code': correct_code})
18
19
20 def migrate(cr, version):
21 env = api.Environment(cr, SUPERUSER_ID, {})
22 _fix_revenue_deduction_accounts_code(env)