|
5 | 5 | import json |
6 | 6 | import logging |
7 | 7 | import os |
| 8 | +from collections import namedtuple |
8 | 9 |
|
9 | | -from odoo import _, api, exceptions, models, tools |
| 10 | +from odoo import SUPERUSER_ID, _, api, exceptions, models, tools |
10 | 11 | from odoo.modules.module import get_module_path |
| 12 | +from odoo.modules.registry import Registry |
11 | 13 |
|
12 | 14 | from ..addon_hash import addon_hash |
13 | 15 |
|
@@ -196,3 +198,23 @@ def upgrade_changed_checksum(self, overwrite_existing_translations=False): |
196 | 198 | "sticky": False, |
197 | 199 | }, |
198 | 200 | } |
| 201 | + |
| 202 | + def upgrade_changed_checksum_shell(self, overwrite_existing_translations=False): |
| 203 | + """Call upgrade_changed_checksum, but in a minimal environment that |
| 204 | + doesn't fail when base models like res.users or ir.model have been changed. |
| 205 | +
|
| 206 | + This function is designed to be called in a shell that ends immediately |
| 207 | + afterwards, as it destroys the current session. |
| 208 | + """ |
| 209 | + fake_module = namedtuple("fake_module", ["name"]) |
| 210 | + self.env.cr.close() |
| 211 | + with self.env.registry.cursor() as _cr: |
| 212 | + Registry.delete_all() |
| 213 | + minimal_registry = object.__new__(Registry) |
| 214 | + minimal_registry.init(_cr.dbname) |
| 215 | + minimal_registry.load(_cr, fake_module("base")) |
| 216 | + minimal_registry.load(_cr, fake_module("module_auto_update")) |
| 217 | + _cr.transaction = api.Transaction(minimal_registry) |
| 218 | + minimal_registry.setup_models(_cr) |
| 219 | + minimal_env = api.Environment(_cr, SUPERUSER_ID, {}) |
| 220 | + minimal_env["ir.module.module"].upgrade_changed_checksum() |
0 commit comments