-
-
Notifications
You must be signed in to change notification settings - Fork 705
/
Copy pathopenupgrade_log.py
63 lines (55 loc) · 2.51 KB
/
openupgrade_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
# Copyright 2011-2015 Therp BV <https://therp.nl>
# Copyright 2016 Opener B.V. <https://opener.am>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib.openupgrade_tools import table_exists
def log_xml_id(cr, module, xml_id):
"""
Log xml_ids at load time in the records table.
Called from:
- tools/convert.py:xml_import._test_xml_id()
- odoo/models.py:BaseModel.load()
- odoo/addons/base/models/ir_model.py:IrModelConstraint._reflect_model()
# Catcha's
- The module needs to be loaded with 'init', or the calling method
won't be called. This can be brought about by installing the
module or updating the 'state' field of the module to 'to install'
or call the server with '--init <module>' and the database argument.
- Do you get the right results immediately when installing the module?
No, sorry. This method retrieves the model from the ir_model_table, but
when the xml id is encountered for the first time, this method is called
before the item is present in this table. Therefore, you will not
get any meaningful results until the *second* time that you 'init'
the module.
- The good news is that the openupgrade_records module that comes
with this distribution allows you to deal with all of this with
one click on the menu item Settings -> Customizations ->
Database Structure -> OpenUpgrade -> Generate Records
- You cannot reinitialize the modules in your production database
and expect to keep working on it happily ever after. Do not perform
this routine on your production database.
:param module: The module that contains the xml_id
:param xml_id: the xml_id, with or without 'module.' prefix
"""
if not table_exists(cr, 'openupgrade_record'):
return
if '.' not in xml_id:
xml_id = '%s.%s' % (module, xml_id)
cr.execute(
"SELECT model FROM ir_model_data "
"WHERE module = %s AND name = %s",
xml_id.split('.'))
record = cr.fetchone()
if not record:
print("Cannot find xml_id %s" % xml_id)
return
else:
cr.execute(
"SELECT id FROM openupgrade_record "
"WHERE module=%s AND model=%s AND name=%s AND type=%s",
(module, record[0], xml_id, 'xmlid'))
if not cr.fetchone():
cr.execute(
"INSERT INTO openupgrade_record "
"(module, model, name, type) values(%s, %s, %s, %s)",
(module, record[0], xml_id, 'xmlid'))