Commit Graph
12 Commits
Author SHA1 Message Date
Xavier Morel 6177b04ce5 [FIX] core: remove unnecessary ast.unparse
Only available in Python 3.9, and for now at least Odoo remains
committed to supporting Python 3.8.

And it's not actually necessary: `literal_eval` supports ast node
input, because internally it just `ast.parse`s the input then
evaluates it, giving it an AST node just skips the parse step.

closes odoo/odoo#135302

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2023-09-13 13:49:38 +00:00
Raphael Collet 132e9f72ed [REF] *: rename onchange2 to onchange
closes odoo/odoo#133049

Related: odoo/enterprise#46240
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-08-31 05:11:44 +00:00
Raphael Collet 26cfa95f11 [IMP] tests: improve fields_spec for web_read() and onchange2() used in Form
This includes the context in fields.

Part-of: odoo/odoo#124614
2023-08-18 19:16:48 +02:00
Raphael Collet 7a86ad8957 [IMP] tests: make Form use onchange2() instead of onchange()
Part-of: odoo/odoo#124614
2023-08-18 19:16:46 +02:00
Raphael Collet aa87c0a6ba [IMP] tests: make Form use web_read() instead of read()
Part-of: odoo/odoo#124614
2023-08-18 19:16:45 +02:00
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
Raphael Collet b33452cd57 [IMP] tests: simplify implementation of Form
- simplify initialization of form._values (don't fill in with False)
- use UpdateDict for form._values (more consistent with x2many values)
- better/simpler API for getting save/onchange/all values
- don't reparse subview in O2MForm (already done by toplevel Form)
- guarantee that one2many fields always have an edition view
- add assignment on many2many fields
- add __getitem__/__setitem__ to access/assign fields with dynamic name

Part-of: odoo/odoo#127400
2023-07-05 18:46:49 +02:00
Julien Mougenot 805197daf9 [IMP] web: Optional start date in daterange fields
Before this commit, the date/datetime/daterange fields only allowed for
an optional end date field. This meant that the primary date was always
the start date.

This commit allows the field to do the opposite: with the primary date
being the end date, and having a `start_date_field` option for an
optional start date.

closes odoo/odoo#120695

Signed-off-by: Michaël Mattiello <mcm@odoo.com>
2023-05-11 09:36:24 +02:00
Julien Mougenot 6cdbce8490 [IMP] form: Support daterange field dependencies
This commit allows the server-side form arch parser used in tests to
also include the "end_date_field" defined in the `options` attribute of
daterange widgets in the dictionnary of fields found in the arch.

The daterange widget is currently the only case where the client adds
another editable field dynamically in the list of known fields. This is
not ideal since the server does not know that when computing the initial
arch sent to the client. The workaround is to also include the
"end_date_field" in the arch with `invisible="1"`, and to add a special
case for the server-side form arch parser used in tests.

Ideally we would want a proper way to define field dependencies in the
arch, but since this widget here is the only use case for that feature
it is better for now to handle it in this simple, more naive way.

Part of task 3121497

closes odoo/odoo#112171

Related: odoo/enterprise#38569
Signed-off-by: Michaël Mattiello <mcm@odoo.com>
2023-05-05 13:52:22 +02:00
Raphael Collet 63ee425b46 [IMP] tests: make server-side Form use get_views()
This aligns the behavior of Form with the web client form view.

Part-of: odoo/odoo#116779
2023-03-31 17:02:43 +02:00
Raphael Collet c93a212213 [IMP] tests: make Form call onchange with the context of the modified field
This aligns the behavior of Form with the web client form view.  Also
simplify the API of method _perform_onchange()

Part-of: odoo/odoo#116779
2023-03-31 17:02:43 +02:00
Raphael Collet 91b3813550 [IMP] tests: improve code of Form
Move its code to file odoo/tests/form.py and make the code more
readable.

Part-of: odoo/odoo#116779
2023-03-31 17:02:43 +02:00