Skip to content

Commit 54e0abe

Browse files
committed
[IMP] util/records.py: allow to add qweb view
logic of key [generation](https://github.com/odoo/odoo/blob/8f72c83168b70eb9ca3b1829de91163ee52003d8/odoo/addons/base/models/ir_ui_view.py#L489) closes #90 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 6ea2cea commit 54e0abe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/util/records.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import re
7+
import uuid
78
from contextlib import contextmanager
89
from operator import itemgetter
910

@@ -272,31 +273,36 @@ def get_trans_terms(value):
272273
)
273274

274275

275-
def add_view(cr, name, model, view_type, arch_db, inherit_xml_id=None, priority=16):
276+
def add_view(cr, name, model, view_type, arch_db, inherit_xml_id=None, priority=16, key=None):
276277
inherit_id = None
277278
if inherit_xml_id:
278279
inherit_id = ref(cr, inherit_xml_id)
279280
if not inherit_id:
280281
raise ValueError(
281282
"Unable to add view '%s' because its inherited view '%s' cannot be found!" % (name, inherit_xml_id)
282283
)
284+
# Odoo <= 8.0 doesn't have the `key`
285+
key_exist = column_exists(cr, "ir_ui_view", "key")
286+
if key_exist and view_type == "qweb" and not key:
287+
key = "gen_key.%s" % str(uuid.uuid4())[:6]
283288
arch_col = "arch_db" if column_exists(cr, "ir_ui_view", "arch_db") else "arch"
284289
jsonb_column = column_type(cr, "ir_ui_view", arch_col) == "jsonb"
285290
arch_column_value = Json({"en_US": arch_db}) if jsonb_column else arch_db
286291
cr.execute(
287292
"""
288293
INSERT INTO ir_ui_view(name, "type", model, inherit_id, mode, active, priority, %s)
289-
VALUES(%%(name)s, %%(view_type)s, %%(model)s, %%(inherit_id)s, %%(mode)s, 't', %%(priority)s, %%(arch_db)s)
294+
VALUES(%%(name)s, %%(view_type)s, %%(model)s, %%(inherit_id)s, %%(mode)s, 't', %%(priority)s, %%(arch_db)s %s)
290295
RETURNING id
291296
"""
292-
% arch_col,
297+
% (arch_col + (", key" if key_exist else ""), ", %(key)s" if key_exist else ""),
293298
{
294299
"name": name,
295300
"view_type": view_type,
296301
"model": model,
297302
"inherit_id": inherit_id,
298303
"mode": "extension" if inherit_id else "primary",
299304
"priority": priority,
305+
"key": key,
300306
"arch_db": arch_column_value,
301307
},
302308
)

0 commit comments

Comments
 (0)