1212]
1313
1414
15+ COA_MAPPING = {
16+ "l10n_ae.uae_chart_template_standard" : "ae" ,
17+ "l10n_ar.l10nar_base_chart_template" : "ar_base" ,
18+ "l10n_ar.l10nar_ex_chart_template" : "ar_ex" ,
19+ "l10n_ar.l10nar_ri_chart_template" : "ar_ri" ,
20+ "l10n_at.l10n_at_chart_template" : "at" ,
21+ "l10n_au.l10n_au_chart_template" : "au" ,
22+ "l10n_be.l10nbe_chart_template" : "be_comp" ,
23+ "l10n_bg.l10n_bg_chart_template" : "bg" ,
24+ "l10n_bo.bo_chart_template" : "bo" ,
25+ "l10n_br.l10n_br_account_chart_template" : "br" ,
26+ "l10n_ca.ca_en_chart_template_en" : "ca_2023" ,
27+ "l10n_ch.l10nch_chart_template" : "ch" ,
28+ "l10n_cl.cl_chart_template" : "cl" ,
29+ "l10n_cn.l10n_chart_china_small_business" : "cn" ,
30+ "l10n_co.l10n_co_chart_template_generic" : "co" ,
31+ "l10n_cr.account_chart_template_0" : "cr" ,
32+ "l10n_cz.cz_chart_template" : "cz" ,
33+ "l10n_de.l10n_de_chart_template" : "de_skr03" ,
34+ "l10n_de.l10n_chart_de_skr04" : "de_skr04" ,
35+ "l10n_de_skr03.l10n_de_chart_template" : "de_skr03" ,
36+ "l10n_de_skr04.l10n_chart_de_skr04" : "de_skr04" ,
37+ "l10n_dk.dk_chart_template" : "dk" ,
38+ "l10n_do.do_chart_template" : "do" ,
39+ "l10n_dz.l10n_dz_pcg_chart_template" : "dz" ,
40+ "l10n_ec.l10n_ec_ifrs" : "ec" ,
41+ "l10n_ee.l10nee_chart_template" : "ee" ,
42+ "l10n_eg.egypt_chart_template_standard" : "eg" ,
43+ "l10n_es.account_chart_template_assoc" : "es_assec" ,
44+ "l10n_es.account_chart_template_common" : "es_common" ,
45+ "l10n_es.account_chart_template_full" : "es_full" ,
46+ "l10n_es.account_chart_template_pymes" : "es_pymes" ,
47+ "l10n_et.l10n_et" : "et" ,
48+ "l10n_fi.fi_chart_template" : "fi" ,
49+ "l10n_fr.l10n_fr_pcg_chart_template" : "fr" ,
50+ "l10n_generic_coa.configurable_chart_template" : "generic_coa" ,
51+ "l10n_gr.l10n_gr_chart_template" : "gr" ,
52+ "l10n_gt.cuentas_plantilla" : "gt" ,
53+ "l10n_hk.l10n_hk_chart_template" : "hk" ,
54+ "l10n_hn.cuentas_plantilla" : "hn" ,
55+ "l10n_hr.l10n_hr_chart_template_rrif" : "hr" ,
56+ "l10n_hr.l10n_hr_euro_chart_template" : "hr" ,
57+ "l10n_hr_kuna.l10n_hr_kuna_chart_template_rrif" : "hr_kuna" ,
58+ "l10n_hu.hungarian_chart_template" : "hu" ,
59+ "l10n_id.l10n_id_chart" : "id" ,
60+ "l10n_ie.l10n_ie" : "ie" ,
61+ "l10n_il.il_chart_template" : "il" ,
62+ "l10n_in.indian_chart_template_standard" : "in" ,
63+ "l10n_it.l10n_it_chart_template_generic" : "it" ,
64+ "l10n_jp.l10n_jp1" : "jp" ,
65+ "l10n_jp.l10n_jp_chart_template" : "jp" ,
66+ "l10n_ke.l10nke_chart_template" : "ke" ,
67+ "l10n_kz.l10nkz_chart_template" : "kz" ,
68+ "l10n_lt.account_chart_template_lithuania" : "lt" ,
69+ "l10n_lu.lu_2011_chart_1" : "lu" ,
70+ "l10n_lv.chart_template_latvia" : "lv" ,
71+ "l10n_ma.l10n_ma_chart_template" : "ma" ,
72+ "l10n_mn.mn_chart_1" : "mn" ,
73+ "l10n_mx.mx_coa" : "mx" ,
74+ "l10n_my.l10n_my_chart_template" : "my" ,
75+ "l10n_mz.l10n_mz_chart_template" : "mz" ,
76+ "l10n_nl.l10nnl_chart_template" : "nl" ,
77+ "l10n_no.no_chart_template" : "no" ,
78+ "l10n_nz.l10n_nz_chart_template" : "nz" ,
79+ "l10n_pa.l10npa_chart_template" : "pa" ,
80+ "l10n_pe.pe_chart_template" : "pe" ,
81+ "l10n_ph.l10n_ph_chart_template" : "ph" ,
82+ "l10n_pk.l10n_pk_chart_template" : "pk" ,
83+ "l10n_pl.pl_chart_template" : "pl" ,
84+ "l10n_pt.pt_chart_template" : "pt" ,
85+ "l10n_ro.ro_chart_template" : "ro" ,
86+ "l10n_rs.l10n_rs_chart_template" : "rs" ,
87+ "l10n_sa.sa_chart_template_standard" : "sa" ,
88+ "l10n_se.l10nse_chart_template" : "se" ,
89+ "l10n_se.l10nse_chart_template_K2" : "se_K2" ,
90+ "l10n_se.l10nse_chart_template_K3" : "se_K3" ,
91+ "l10n_sg.sg_chart_template" : "sg" ,
92+ "l10n_si.gd_chart" : "si" ,
93+ "l10n_sk.sk_chart_template" : "sk" ,
94+ "l10n_syscohada.syscohada_chart_template" : "syscohada" ,
95+ "l10n_th.chart" : "th" ,
96+ "l10n_tr.chart_template_common" : "tr" ,
97+ "l10n_tr.l10n_tr_chart_template" : "tr" ,
98+ "l10n_tw.l10n_tw_chart_template" : "tw" ,
99+ "l10n_ua.l10n_ua_ias_chart_template" : "ua_ias" ,
100+ "l10n_ua.l10n_ua_psbo_chart_template" : "ua_psbo" ,
101+ "l10n_uk.l10n_uk" : "uk" ,
102+ "l10n_uy.uy_chart_template" : "uy" ,
103+ "l10n_ve.ve_chart_template_amd" : "ve" ,
104+ "l10n_vn.vn_template" : "vn" ,
105+ "l10n_za.default_chart_template" : "za" ,
106+ }
107+
108+
15109def _am_update_invoice_pdf_report_file (env ):
16110 openupgrade .logged_query (
17111 env .cr ,
@@ -395,6 +489,35 @@ def _force_install_account_payment_term_module_module(env):
395489 )
396490
397491
492+ def _map_chart_template_id_to_chart_template (
493+ env , model_table , coa_m2o = "chart_template_id" , coa_name_column = "chart_template"
494+ ):
495+ """
496+ In tables that used to refer to a chart template in the database, set the new
497+ column identitying the COA by the name of its localization module with the
498+ `l10n_` prefix removed (usually the country's iso code)
499+ """
500+ env .cr .execute (
501+ f"""SELECT m.id, CONCAT(imd.module, '.', imd.name)
502+ FROM { model_table } m
503+ JOIN ir_model_data imd
504+ ON imd.model='account.chart.template'
505+ AND m.{ coa_m2o } = imd.res_id
506+ WHERE m.{ coa_m2o } IS NOT NULL
507+ AND CONCAT(imd.module, '.', imd.name) IN %s
508+ """ ,
509+ (tuple (COA_MAPPING ),),
510+ )
511+ chart_id2name = [(_id , COA_MAPPING [xmlid ]) for _id , xmlid in env .cr .fetchall ()]
512+ openupgrade .map_values (
513+ env .cr ,
514+ coa_m2o ,
515+ coa_name_column ,
516+ chart_id2name ,
517+ table = model_table ,
518+ )
519+
520+
398521@openupgrade .migrate ()
399522def migrate (env , version ):
400523 _account_payment_term_migration (env )
@@ -408,3 +531,5 @@ def migrate(env, version):
408531 _am_update_invoice_pdf_report_file (env )
409532 _onboarding_state_migration (env )
410533 _account_tax_group_migration (env )
534+ _map_chart_template_id_to_chart_template (env , "res_company" )
535+ _map_chart_template_id_to_chart_template (env , "account_report" )
0 commit comments