Do not mix base views and extensions

Closes #13056
This commit is contained in:
Cédric Krier
2024-02-25 13:31:48 +01:00
parent adb7243f0c
commit 0b431b0ce1
5 changed files with 67 additions and 3 deletions
+47 -1
View File
@@ -4,6 +4,7 @@ import json
import os
from lxml import etree
from sql import Literal, Null
from trytond.cache import Cache, MemoryCache
from trytond.i18n import gettext
@@ -70,8 +71,22 @@ class View(
arch = fields.Function(fields.Text('View Architecture', states={
'readonly': Bool(Eval('name')),
}, depends=['name']), 'get_arch', setter='set_arch')
basis = fields.Function(fields.Boolean("Basis"), 'get_basis')
inherit = fields.Many2One('ir.ui.view', 'Inherited View',
ondelete='CASCADE')
extensions = fields.One2Many(
'ir.ui.view', 'inherit', "Extensions",
filter=[
('basis', '=', False),
],
domain=[
('model', '=', Eval('model')),
('type', '=', None),
],
states={
'invisible': ~Eval('type'),
},
order=[('id', None)])
field_childs = fields.Char('Children Field', states={
'invisible': Eval('type') != 'tree',
}, depends=['type'])
@@ -95,7 +110,8 @@ class View(
cls._buttons.update({
'show': {
'readonly': Eval('type') != 'form',
'depends': ['type'],
'invisible': ~Eval('basis', False),
'depends': ['type', 'basis'],
},
})
cls._sql_indexes.update({
@@ -116,6 +132,36 @@ class View(
def default_module():
return Transaction().context.get('module') or ''
def get_basis(self, name):
return not self.inherit or self.model != self.inherit.model
@classmethod
def domain_basis(cls, domain, tables):
table, _ = tables[None]
if 'inherit' not in tables:
inherit = cls.__table__()
tables['inherit'] = {
None: (inherit, table.inherit == inherit.id),
}
else:
inherit, _ = tables['inherit'][None]
expression = (table.inherit == Null) | (table.model != inherit.model)
_, operator, value = domain
if operator in {'=', '!='}:
if (operator == '=') != value:
expression = ~expression
elif operator in {'in', 'not in'}:
if True in value and False not in value:
pass
elif False in value and True not in value:
expression = ~expression
else:
expression = Literal(True)
else:
expression = Literal(True)
return expression
def get_rec_name(self, name):
return '%s (%s)' % (
self.model_ref.rec_name,
+9
View File
@@ -17,12 +17,21 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.ui.view" id="view_view_tree">
<field name="model">ir.ui.view</field>
<field name="type">tree</field>
<field name="priority" eval="10"/>
<field name="name">ui_view_list</field>
</record>
<record model="ir.ui.view" id="view_view_list_extension">
<field name="model">ir.ui.view</field>
<field name="type">tree</field>
<field name="priority" eval="20"/>
<field name="name">ui_view_list_extension</field>
</record>
<record model="ir.action.act_window" id="act_view_form">
<field name="name">Views</field>
<field name="type">ir.action.act_window</field>
<field name="res_model">ir.ui.view</field>
<field name="domain" eval="[('basis', '=', True)]" pyson="1"/>
<field name="order" eval="[('model', None)]" pyson="1"/>
</record>
<record model="ir.action.act_window.view"
id="act_view_form_view1">
+1
View File
@@ -20,5 +20,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="name"/>
<separator name="arch" colspan="4"/>
<field name="arch" colspan="4"/>
<field name="extensions" colspan="4" view_ids="ir.view_view_list_extension"/>
<button name="show" colspan="4"/>
</form>
+1 -2
View File
@@ -5,8 +5,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="priority" optional="1"/>
<field name="model_ref" expand="2"/>
<field name="type"/>
<field name="inherit" expand="1" optional="0"/>
<field name="domain" expand="1" optional="1"/>
<field name="inherit" expand="1" optional="1"/>
<field name="field_children" optional="1"/>
<field name="module_ref" optional="1"/>
</tree>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="rec_name" expand="1"/>
<field name="domain" expand="1" optional="0"/>
<field name="module" optional="1"/>
<field name="name" optional="1"/>
</tree>