|
| 1 | +# Copyright 2023 Simone Rubino - Aion Tech |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
| 3 | + |
| 4 | +from openupgradelib import openupgrade |
| 5 | + |
| 6 | +from odoo.tools import DotDict |
| 7 | + |
| 8 | +RENAMED_FIELDS = [ |
| 9 | + [ |
| 10 | + ( |
| 11 | + "account.invoice", |
| 12 | + "note", |
| 13 | + ), |
| 14 | + ( |
| 15 | + "account.move", |
| 16 | + "delivery_note", |
| 17 | + ), |
| 18 | + ], |
| 19 | + [ |
| 20 | + ( |
| 21 | + "account.invoice", |
| 22 | + "date_done", |
| 23 | + ), |
| 24 | + ( |
| 25 | + "account.move", |
| 26 | + "delivery_transport_datetime", |
| 27 | + ), |
| 28 | + ], |
| 29 | + [ |
| 30 | + ( |
| 31 | + "account.invoice", |
| 32 | + "carriage_condition_id", |
| 33 | + ), |
| 34 | + ( |
| 35 | + "account.move", |
| 36 | + "delivery_transport_condition_id", |
| 37 | + ), |
| 38 | + ], |
| 39 | + [ |
| 40 | + ( |
| 41 | + "account.invoice", |
| 42 | + "goods_description_id", |
| 43 | + ), |
| 44 | + ( |
| 45 | + "account.move", |
| 46 | + "delivery_goods_appearance_id", |
| 47 | + ), |
| 48 | + ], |
| 49 | + [ |
| 50 | + ( |
| 51 | + "account.invoice", |
| 52 | + "transportation_reason_id", |
| 53 | + ), |
| 54 | + ( |
| 55 | + "account.move", |
| 56 | + "delivery_transport_reason_id", |
| 57 | + ), |
| 58 | + ], |
| 59 | + [ |
| 60 | + ( |
| 61 | + "account.invoice", |
| 62 | + "transportation_method_id", |
| 63 | + ), |
| 64 | + ( |
| 65 | + "account.move", |
| 66 | + "delivery_transport_method_id", |
| 67 | + ), |
| 68 | + ], |
| 69 | + [ |
| 70 | + ( |
| 71 | + "account.invoice", |
| 72 | + "carrier_id", |
| 73 | + ), |
| 74 | + ( |
| 75 | + "account.move", |
| 76 | + "delivery_carrier_id", |
| 77 | + ), |
| 78 | + ], |
| 79 | + [ |
| 80 | + ( |
| 81 | + "account.invoice", |
| 82 | + "parcels", |
| 83 | + ), |
| 84 | + ( |
| 85 | + "account.move", |
| 86 | + "delivery_packages", |
| 87 | + ), |
| 88 | + ], |
| 89 | + [ |
| 90 | + ( |
| 91 | + "account.invoice", |
| 92 | + "weight", |
| 93 | + ), |
| 94 | + ( |
| 95 | + "account.move", |
| 96 | + "delivery_net_weight", |
| 97 | + ), |
| 98 | + ], |
| 99 | + [ |
| 100 | + ( |
| 101 | + "account.invoice", |
| 102 | + "gross_weight", |
| 103 | + ), |
| 104 | + ( |
| 105 | + "account.move", |
| 106 | + "delivery_gross_weight", |
| 107 | + ), |
| 108 | + ], |
| 109 | + [ |
| 110 | + ( |
| 111 | + "account.invoice", |
| 112 | + "volume", |
| 113 | + ), |
| 114 | + ( |
| 115 | + "account.move", |
| 116 | + "delivery_volume", |
| 117 | + ), |
| 118 | + ], |
| 119 | + [ |
| 120 | + ( |
| 121 | + "account.invoice", |
| 122 | + "weight_manual_uom_id", |
| 123 | + ), |
| 124 | + ( |
| 125 | + "account.move", |
| 126 | + "delivery_net_weight_uom_id", |
| 127 | + ), |
| 128 | + ], |
| 129 | + [ |
| 130 | + ( |
| 131 | + "account.invoice", |
| 132 | + "gross_weight_uom_id", |
| 133 | + ), |
| 134 | + ( |
| 135 | + "account.move", |
| 136 | + "delivery_gross_weight_uom_id", |
| 137 | + ), |
| 138 | + ], |
| 139 | + [ |
| 140 | + ( |
| 141 | + "account.invoice", |
| 142 | + "volume_uom_id", |
| 143 | + ), |
| 144 | + ( |
| 145 | + "account.move", |
| 146 | + "delivery_volume_uom_id", |
| 147 | + ), |
| 148 | + ], |
| 149 | +] |
| 150 | + |
| 151 | +RENAMED_XMLIDS = [ |
| 152 | + ( |
| 153 | + "invoice_form_view_uom", |
| 154 | + "view_move_form", |
| 155 | + ), |
| 156 | + ( |
| 157 | + "invoice_form_view_uom", |
| 158 | + "shipping_invoice_report", |
| 159 | + ), |
| 160 | + ( |
| 161 | + "invoice_form_view_uom", |
| 162 | + "shipping_invoice_template", |
| 163 | + ), |
| 164 | + ( |
| 165 | + "invoice_form_view_uom", |
| 166 | + "report_shipping_invoice", |
| 167 | + ), |
| 168 | +] |
| 169 | + |
| 170 | + |
| 171 | +# def remove_models(cr, model_spec): |
| 172 | +# for name in model_spec: |
| 173 | +# logged_query( |
| 174 | +# cr, |
| 175 | +# "DELETE FROM ir_model WHERE model = %s", |
| 176 | +# (name,), |
| 177 | +# ) |
| 178 | + |
| 179 | + |
| 180 | +def migrate_old_module(cr): |
| 181 | + field_spec = [] |
| 182 | + for renamed_field in RENAMED_FIELDS: |
| 183 | + (old_model, old_field), (new_model, new_field) = renamed_field |
| 184 | + field_spec.append( |
| 185 | + ( |
| 186 | + old_model, |
| 187 | + old_model.replace(".", "_"), |
| 188 | + old_field, |
| 189 | + new_field, |
| 190 | + ) |
| 191 | + ) |
| 192 | + openupgrade.rename_fields( |
| 193 | + # The method only needs the cursor, not the whole Environment |
| 194 | + DotDict( |
| 195 | + cr=cr, |
| 196 | + ), |
| 197 | + field_spec, |
| 198 | + # Prevent Environment usage |
| 199 | + # whenever it will be implemented. |
| 200 | + no_deep=True, |
| 201 | + ) |
| 202 | + |
| 203 | + full_renamed_xmlids = [ |
| 204 | + ( |
| 205 | + ".".join(("l10n_it_accompanying_invoice", old_xmlid)), |
| 206 | + ".".join(("l10n_it_accompanying_invoice", new_xmlid)), |
| 207 | + ) |
| 208 | + for old_xmlid, new_xmlid in RENAMED_XMLIDS |
| 209 | + ] |
| 210 | + openupgrade.rename_xmlids( |
| 211 | + cr, |
| 212 | + full_renamed_xmlids, |
| 213 | + ) |
| 214 | + |
| 215 | + |
| 216 | +def pre_absorb_old_module(cr): |
| 217 | + if openupgrade.is_module_installed(cr, "l10n_it_accompanying_invoice"): |
| 218 | + openupgrade.update_module_names( |
| 219 | + cr, |
| 220 | + [ |
| 221 | + ("l10n_it_fattura_accompagnatoria", "l10n_it_accompanying_invoice"), |
| 222 | + ], |
| 223 | + merge_modules=True, |
| 224 | + ) |
| 225 | + migrate_old_module(cr) |
0 commit comments