Files
odoo_source/odoo/addons/test_testing_utilities/menu.xml
T
Gorash cdaa761ced [REF] base: Update modifier syntax (invisible, required, readonly)
Goal:
* Simplified modifiers to only have one way to define modifiers;
* Remove states attributes on python field;
* Use python expression in view `required`, `readonly`, `invisible`;
* More accurate validation of xml views.

This commit change the syntax to python expression. The next commit
will update/convert all xml views.

Before this commit:
* the `required`, `readonly` and `invisible` attributes can only have
values of `True`, `False`, 1, 0 or a python expression to use the
context;
* the `attrs` attribute define a dict. The key of this dict was
`required`, `readonly` and `invisible` and the values are the domain or
a string representing a domain to be evaluate as python expression.
This python expressions was evaluate by the javascript with view fields
and other contextual values as: context, uid, parent, active_id,
active_ids, active_model, allowed_company_ids, current_company_id.
* the `states` attribute in the view was a comma separated list of the
state. This list was combined with the `invisible` attribute;
* the `invisible` attribute on python field is used as default value;
* the `states` attribute on python field was dictionnary with state as
key and list of tuple. This structure was combined with `readonly` view
attribute.
* After combining, the resulting domains of the different attributes
`required`, `readonly` and `invisible` are evaluated with the values of
the fields. The `invisible` attributes is splitted into two use:
`invisible` and `column_invisible`.

After this commit:
* The attributes `required`, `readonly`, `invisible` and
`column_invisible` define python expression. This python expressions
are evaluate by the javascript with view fields and other contextual
values as: context, uid, parent, active_id, active_ids, active_model,
allowed_company_ids, current_company_id.

The domains can contains contextual value and will be evaluate by the
javascript.

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'readonly': [('field_b', '!=', False), ('field_c', '=', parent.c)]}"/>
    <field name="field_b" states="draft"/>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a') or field_b and field_c == parent.c"/>
    <field name="field_b" invisible="state != 'draft'"/>
```

Some inherited views will be modified differently in order to maintain
the previous behavior:

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'invisible': [('field_b', '!=', False)]}">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="attrs">{'readonly': [('field_c', '=', False)], 'invisible': [('field_d', '!=', '3')]}<attribute>
    </field>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a')" invisible="field_b">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="readonly" add="(not field_c)" separator=" or "/>
        <attribute name="invisible">field_d != 3<attribute>
    </field>
```

Validation:
A stricter control is made on the level of the attributes (modifiers)
and the fields necessary for these. The use of the previous attributes
'attr' and 'states' triggers an error (these no longer exist after the
application of the migration script)

task-2495504

Part-of: odoo/odoo#104741
2023-08-18 09:49:08 +02:00

308 lines
11 KiB
XML

<odoo>
<menuitem id="menu_ssf" parent="base.menu_tests" name="Server-side form"/>
<record id="action_test_o2m_onchange" model="ir.actions.act_window">
<field name="name">Test o2m onchange thing</field>
<field name="res_model">test_testing_utilities.parent</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_o2m" parent="menu_ssf"
name="O2M onchange test thing"
action="action_test_o2m_onchange"/>
<record id="action_test_m2o_onchange" model="ir.actions.act_window">
<field name="name">test_default_and_onchange</field>
<field name="res_model">test_testing_utilities.d</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_m2o" parent="menu_ssf"
name="test_default_and_onchange"
action="action_test_m2o_onchange"/>
<record id="action_test_o2m_count" model="ir.actions.act_window">
<field name="name">test_change_number_of_lines</field>
<field name="res_model">test_testing_utilities.onchange_count</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_o2m_count" parent="menu_ssf"
name="test_change_number_of_lines"
action="action_test_o2m_count"/>
<record id="o2m_parent" model="ir.ui.view">
<field name="name">Parent External Form</field>
<field name="priority">1</field>
<field name="model">test_testing_utilities.parent</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="value"/>
<field name="v"/>
</group>
<group>
<field name="subs"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="o2m_parent_readonly" model="ir.ui.view">
<field name="name">Parent readonly o2m field</field>
<field name="model">test_testing_utilities.parent</field>
<field name="inherit_id" ref="o2m_parent"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='subs']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>
</field>
</record>
<record id="o2m_tree" model="ir.ui.view">
<field name="name">Sub regular</field>
<field name="priority">1</field>
<field name="model">test_testing_utilities.sub</field>
<field name="arch" type="xml">
<tree>
<field name="value"/>
<field name="v"/>
<field name="name"/>
</tree>
</field>
</record>
<record id="o2m_parent_ed" model="ir.ui.view">
<field name="name">Parent External Tree</field>
<field name="model">test_testing_utilities.parent</field>
<field name="arch" type="xml">
<form>
<field name="value"/>
<field name="v"/>
<field name="subs" context="{'tree_view_ref': 'test_testing_utilities.editable_external'}"/>
</form>
</field>
</record>
<record id="editable_external" model="ir.ui.view">
<field name="name">Sub regular</field>
<field name="model">test_testing_utilities.sub</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="value"/>
<field name="v"/>
<field name="name"/>
</tree>
</field>
</record>
<record id="o2m_parent_inline" model="ir.ui.view">
<field name="name">Parent Inline Tree</field>
<field name="model">test_testing_utilities.parent</field>
<field name="arch" type="xml">
<form>
<field name="value"/>
<field name="v"/>
<field name="subs">
<tree editable="bottom">
<field name="value"/>
<field name="name"/>
</tree>
</field>
</form>
</field>
</record>
<record id="o2m_parent_context" model="ir.ui.view">
<field name="name">Parent Inline Tree with context on field</field>
<field name="model">test_testing_utilities.parent</field>
<field name="arch" type="xml">
<form>
<field name="value"/>
<field name="v"/>
<field name="subs">
<tree editable="bottom">
<field name="value" context="{'parent_value': parent.value}"/>
<field name="name"/>
</tree>
</field>
</form>
</field>
</record>
<record id="non_normalized_attrs" model="ir.ui.view">
<field name="name">Non Normalised Domains</field>
<field name="model">test_testing_utilities.a</field>
<field name="arch" type="xml">
<form>
<field name="f1"/>
<field name="f2" attrs="{'readonly': [['f1', '=', '63'], ['f3', '=', 5]]}"/>
<field name="f3"/>
<field name="f4"/>
<field name="f5" readonly="True"/>
<field name="f6" readonly="1" force_save="1"/>
</form>
</field>
</record>
<record id="m2o_onchange_view" model="ir.ui.view">
<field name="name">Dynamic Onchange Test View</field>
<field name="model">test_testing_utilities.onchange_parent</field>
<field name="arch" type="xml">
<form>
<sheet>
<notebook>
<page>
<field name="line_ids" widget="one2many" context="{'line_ids': line_ids}">
<tree editable="bottom">
<field name="dummy"/>
<field name="flag" invisible="1" readonly="1"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="m2m_change_view" model="ir.ui.view">
<field name="name">M2M Change View</field>
<field name="model">test_testing_utilities.f</field>
<field name="arch" type="xml">
<form>
<field name="m2o"/>
<field name="m2m" nolabel="1">
<tree>
<field name="name"/>
<field name="m2o_ids" widget="many2many_tags"/>
</tree>
<form>
<field name="name"/>
<field name="m2o_ids">
<tree>
<field name="name"/>
</tree>
</field>
</form>
</field>
</form>
</field>
</record>
<record id="o2m_recursive_relation_view" model="ir.ui.view">
<field name="name">Recursive Relation Test View</field>
<field name="model">test_testing_utilities.recursive</field>
<field name="arch" type="xml">
<form>
<sheet>
<field name="one_to_many_id"/>
<field name="many_to_one_ids"/>
</sheet>
</form>
</field>
</record>
<record id="o2m_modifier" model="ir.ui.view">
<field name="name">Modifier check</field>
<field name="model">test_testing_utilities.parent</field>
<field name="inherit_id" ref="o2m_parent"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="subs" position="inside">
<form>
<field name="value" attrs="{'readonly': [('v', '=', 42)]}"/>
<field name="v"/>
</form>
</field>
</field>
</record>
<record id="o2m_modifier_parent" model="ir.ui.view">
<field name="name">Modifier check</field>
<field name="model">test_testing_utilities.parent</field>
<field name="inherit_id" ref="o2m_parent"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="subs" position="inside">
<form>
<field name="value" attrs="{'readonly': [('parent.value', '=', 42)]}"/>
<field name="v"/>
</form>
</field>
</field>
</record>
<record id="o2m_modifier_ref" model="ir.ui.view">
<field name="name">Modifier check</field>
<field name="model">test_testing_utilities.ref</field>
<field name="arch" type="xml">
<form>
<field name="value"/>
<field name="subs"
invisible="value == 666"
context="{
'tree_view_ref': 'test_testing_utilities.o2m_modifier_ref_sub_tree',
'hide_c': True
}"/>
</form>
</field>
</record>
<record id="o2m_modifier_ref_sub_form" model="ir.ui.view">
<field name="name">Sub form view</field>
<field name="model">test_testing_utilities.ref.sub</field>
<field name="arch" type="xml">
<form>
<field name="c"/>
</form>
</field>
</record>
<record id="o2m_modifier_ref_sub_wrong" model="ir.ui.view">
<field name="name">Sub tree view</field>
<field name="model">test_testing_utilities.ref.sub</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="c"/>
</tree>
</field>
</record>
<record id="o2m_modifier_ref_sub_tree" model="ir.ui.view">
<field name="name">Sub tree view</field>
<field name="model">test_testing_utilities.ref.sub</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<tree editable="bottom">
<field name="a"/>
<field name="b" readonly="parent.value == 42"/>
<field name="c" invisible="context.get('hide_c')"/>
</tree>
</field>
</record>
<record id="o2m_widget_m2m" model="ir.ui.view">
<field name="name">Treat o2m as m2m</field>
<field name="model">test_testing_utilities.parent</field>
<field name="inherit_id" ref="o2m_parent"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="subs" position="attributes">
<attribute name="widget">many2many</attribute>
</field>
</field>
</record>
<record id="attrs_using_m2m" model="ir.ui.view">
<field name="name">Check readonly using an m2m value</field>
<field name="model">test_testing_utilities.e</field>
<field name="arch" type="xml">
<form>
<field name="count" attrs="{'readonly': [('m2m', '=', [])]}"/>
<field name="m2m"/>
</form>
</field>
</record>
</odoo>