Skip to content

Commit

Permalink
[IMP] util/records.py: allow to add qweb view
Browse files Browse the repository at this point in the history
  • Loading branch information
hpr-odoo committed May 31, 2024
1 parent 6ea2cea commit 54e0abe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import re
import uuid
from contextlib import contextmanager
from operator import itemgetter

Expand Down Expand Up @@ -272,31 +273,36 @@ def get_trans_terms(value):
)


def add_view(cr, name, model, view_type, arch_db, inherit_xml_id=None, priority=16):
def add_view(cr, name, model, view_type, arch_db, inherit_xml_id=None, priority=16, key=None):
inherit_id = None
if inherit_xml_id:
inherit_id = ref(cr, inherit_xml_id)
if not inherit_id:
raise ValueError(
"Unable to add view '%s' because its inherited view '%s' cannot be found!" % (name, inherit_xml_id)
)
# Odoo <= 8.0 doesn't have the `key`
key_exist = column_exists(cr, "ir_ui_view", "key")
if key_exist and view_type == "qweb" and not key:
key = "gen_key.%s" % str(uuid.uuid4())[:6]
arch_col = "arch_db" if column_exists(cr, "ir_ui_view", "arch_db") else "arch"
jsonb_column = column_type(cr, "ir_ui_view", arch_col) == "jsonb"
arch_column_value = Json({"en_US": arch_db}) if jsonb_column else arch_db
cr.execute(
"""
INSERT INTO ir_ui_view(name, "type", model, inherit_id, mode, active, priority, %s)
VALUES(%%(name)s, %%(view_type)s, %%(model)s, %%(inherit_id)s, %%(mode)s, 't', %%(priority)s, %%(arch_db)s)
VALUES(%%(name)s, %%(view_type)s, %%(model)s, %%(inherit_id)s, %%(mode)s, 't', %%(priority)s, %%(arch_db)s %s)
RETURNING id
"""
% arch_col,
% (arch_col + (", key" if key_exist else ""), ", %(key)s" if key_exist else ""),
{
"name": name,
"view_type": view_type,
"model": model,
"inherit_id": inherit_id,
"mode": "extension" if inherit_id else "primary",
"priority": priority,
"key": key,
"arch_db": arch_column_value,
},
)
Expand Down

0 comments on commit 54e0abe

Please sign in to comment.