|
4 | 4 | import logging |
5 | 5 | import os |
6 | 6 | import re |
| 7 | +import uuid |
7 | 8 | from contextlib import contextmanager |
8 | 9 | from operator import itemgetter |
9 | 10 |
|
@@ -272,31 +273,36 @@ def get_trans_terms(value): |
272 | 273 | ) |
273 | 274 |
|
274 | 275 |
|
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): |
276 | 277 | inherit_id = None |
277 | 278 | if inherit_xml_id: |
278 | 279 | inherit_id = ref(cr, inherit_xml_id) |
279 | 280 | if not inherit_id: |
280 | 281 | raise ValueError( |
281 | 282 | "Unable to add view '%s' because its inherited view '%s' cannot be found!" % (name, inherit_xml_id) |
282 | 283 | ) |
| 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] |
283 | 288 | arch_col = "arch_db" if column_exists(cr, "ir_ui_view", "arch_db") else "arch" |
284 | 289 | jsonb_column = column_type(cr, "ir_ui_view", arch_col) == "jsonb" |
285 | 290 | arch_column_value = Json({"en_US": arch_db}) if jsonb_column else arch_db |
286 | 291 | cr.execute( |
287 | 292 | """ |
288 | 293 | 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) |
290 | 295 | RETURNING id |
291 | 296 | """ |
292 | | - % arch_col, |
| 297 | + % (arch_col + (", key" if key_exist else ""), ", %(key)s" if key_exist else ""), |
293 | 298 | { |
294 | 299 | "name": name, |
295 | 300 | "view_type": view_type, |
296 | 301 | "model": model, |
297 | 302 | "inherit_id": inherit_id, |
298 | 303 | "mode": "extension" if inherit_id else "primary", |
299 | 304 | "priority": priority, |
| 305 | + "key": key, |
300 | 306 | "arch_db": arch_column_value, |
301 | 307 | }, |
302 | 308 | ) |
|
0 commit comments