@@ -78,7 +78,8 @@ class BiSQLView(models.Model):
78
78
readonly = False ,
79
79
states = {"ui_valid" : [("readonly" , True )]},
80
80
default = "pivot,graph,tree" ,
81
- help = "Comma-separated text. Possible values:" ' "graph", "pivot" or "tree"' ,
81
+ help = "Comma-separated text. Possible values:"
82
+ ' "graph", "pivot", "tree" or "form"' ,
82
83
)
83
84
84
85
query = fields .Text (
@@ -126,6 +127,7 @@ class BiSQLView(models.Model):
126
127
model_id = fields .Many2one (
127
128
string = "Odoo Model" , comodel_name = "ir.model" , readonly = True
128
129
)
130
+
129
131
# UI related fields
130
132
# 1. Editable fields, which can be set by the user (optional) before
131
133
# creating the UI elements
@@ -151,6 +153,11 @@ def _default_parent_menu_id(self):
151
153
)
152
154
153
155
# 2. Readonly fields, non editable by the user
156
+
157
+ form_view_id = fields .Many2one (
158
+ string = "Odoo Form View" , comodel_name = "ir.ui.view" , readonly = True
159
+ )
160
+
154
161
tree_view_id = fields .Many2one (
155
162
string = "Odoo Tree View" , comodel_name = "ir.ui.view" , readonly = True
156
163
)
@@ -207,9 +214,9 @@ def _check_view_order(self):
207
214
for rec in self :
208
215
if rec .view_order :
209
216
for vtype in rec .view_order .split ("," ):
210
- if vtype not in ("graph" , "pivot" , "tree" ):
217
+ if vtype not in ("graph" , "pivot" , "tree" , "form" ):
211
218
raise UserError (
212
- _ ("Only graph, pivot or tree views are supported" )
219
+ _ ("Only graph, pivot, tree or form views are supported" )
213
220
)
214
221
215
222
# Compute Section
@@ -324,6 +331,7 @@ def button_create_sql_view_and_model(self):
324
331
325
332
def button_reset_to_model_valid (self ):
326
333
views = self .filtered (lambda x : x .state == "ui_valid" )
334
+ views .mapped ("form_view_id" ).unlink ()
327
335
views .mapped ("tree_view_id" ).unlink ()
328
336
views .mapped ("graph_view_id" ).unlink ()
329
337
views .mapped ("pivot_view_id" ).unlink ()
@@ -351,6 +359,7 @@ def button_set_draft(self):
351
359
return super ().button_set_draft ()
352
360
353
361
def button_create_ui (self ):
362
+ self .form_view_id = self .env ["ir.ui.view" ].create (self ._prepare_form_view ()).id
354
363
self .tree_view_id = self .env ["ir.ui.view" ].create (self ._prepare_tree_view ()).id
355
364
self .graph_view_id = (
356
365
self .env ["ir.ui.view" ].create (self ._prepare_graph_view ()).id
@@ -442,6 +451,19 @@ def _prepare_rule(self):
442
451
"global" : True ,
443
452
}
444
453
454
+ def _prepare_form_view (self ):
455
+ self .ensure_one ()
456
+ return {
457
+ "name" : self .name ,
458
+ "type" : "form" ,
459
+ "model" : self .model_id .model ,
460
+ "arch" : """<?xml version="1.0"?>"""
461
+ """<form><sheet><group string="Data" col="4">{}"""
462
+ """</group></sheet></form>""" .format (
463
+ "" .join ([x ._prepare_form_field () for x in self .bi_sql_view_field_ids ])
464
+ ),
465
+ }
466
+
445
467
def _prepare_tree_view (self ):
446
468
self .ensure_one ()
447
469
return {
@@ -507,6 +529,8 @@ def _prepare_action(self):
507
529
self .ensure_one ()
508
530
view_mode = self .view_order
509
531
first_view = view_mode .split ("," )[0 ]
532
+ if first_view == "form" :
533
+ view_id = self .form_view_id .id
510
534
if first_view == "tree" :
511
535
view_id = self .tree_view_id .id
512
536
elif first_view == "pivot" :
0 commit comments