Commit Graph
17 Commits
Author SHA1 Message Date
Gorash 774a3fad0e [REF] base,all: Update modifier syntax: view migration
Apply of the migration script to update all view modifiers.

Part-of: odoo/odoo#104741
2023-08-18 09:49:13 +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 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
Victor Feyens 24ccf7d9b0 [CLN] *: useless type info for actions
The type fields of actions already defaults to
the model name in the base model definition.

Therefore, specifying `ir.actions.server`, `ir.actions.act_window`
& so on as type is useless (and adds noise since it's the same as
the action model).

closes odoo/odoo#114539

Related: odoo/enterprise#37855
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
2023-03-08 17:33:37 +01:00
Xavier ALT af2eaae941 [FIX] core: add UPDATE as valid many2many command in SSF
This commit fix the "Unsupported M2M command 1" raised `Form` helper.

The `onchange()` method will in fact emit UPDATE command for many2many
fields when the value submitted an the one in database has changed
(this is the case for example for nested m2m in form views)

OPW-2044631

closes odoo/odoo#59943

X-original-commit: 76bd8208a416cefab6becff9f2d7204c7d196201
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Signed-off-by: Xavier ALT <xavieralt@users.noreply.github.com>
2020-10-14 08:23:22 +00:00
Luis González 4debe9f1fa [FIX] tests: Handle attrs containing numbers instead of bool
The Form class already handles cases for attrs that contain boolean
values, e.g.:
`attrs="{'readonly': True}"`

But it doesnt for integers, e.g.:
`attrs="{'readonly': 1}"`

This commit changes the expected non-domain value from boolean to
integer, because both are valid cases and the former is a subset of the
latter.

[1] https://github.com/odoo/odoo/blob/b3d4938ba6b1/addons/repair/views/repair_views.xml#L54

closes odoo/odoo#56612

X-original-commit: 782534a429f10e7b114c838687d38aa4080a920c
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Signed-off-by: Luis González [Vauxoo] <luisg123v@users.noreply.github.com>
2020-08-26 15:36:43 +00:00
Xavier Morel a480398bf3 [FIX] SSF: modifier based on m2m value
m2ms are internally represented as "6" commands, however in domains
it's possible to compare an m2m value to a list of ids (to
investigate: whether this is an artifact of internal webclient repr or
part of the real contract).

Add a workaround in SSF modifier computation to convert the m2m
command storage to a simple ids list.

A better fix would probably have been to represent the m2m as a list
of ids internally (and only convert on load / save) however it not
completely trivial as it has to be done recursively in order to
properly handle an m2m inside an o2m. So it's a complete change of the
internal data model (which should probably go alongide more
fundamental changes e.g. properly handling parent refs, etc...)

Also add very minor support for widgets (mostly so it's possible to
set widget=many2many on an o2m field).

closes odoo/odoo#39467

X-original-commit: 927979beff9e5d4f6c88078862779eaa88f4e07d
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-10-28 16:03:39 +00:00
Xavier Morel 77099c54b6 [FIX] core: o2m modifiers in the SSF
Because the sub-record values would not necessarily get fetched
ever (whether default or stored), the computation of modifiers might
blow up if it relied on one of the un-fetched un-specified fields.

One such situation is trying to create a partner with child partners
if base_address_city is installed: the module adds a readonly attr
predicated upon the parent_id, without explicitly providing such the
field would be missing from the O2M record's values.

Closes #37176

closes odoo/odoo#37452

X-original-commit: 184d1b69eac2b78c72228c81c5c6cf8cc4a56eb4
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-09-25 16:37:19 +00:00
Martin Geubelle 0aa4906843 [REF] web, *: remove one2many_list widget
This widget was exactly the same as a `one2many` and was kept for backward
compatibility reasons. It can be safely removed in master.

Related to task 1918327
2019-04-24 08:04:39 +00:00
Xavier Morel 922d77a291 [FIX] core: infinite recursion in SSF on self-recursive models
The extra setup probably affects any o2m whose edition view itself
contains an o2m, but most likely to blow up entirely on models with
some sort of tree structure (parent/child relationship): the SSF
eagerly loads and setups the o2m's view, and the o2m's o2m's, ... ad
infinitam.

A better / cleaner fix would be to set up the subview on-demand (and
possibly cache it), but the rest of the o2m stuff is unlikely to work
correctly recursively so just don't recurse the o2m view setup at all
for now.

fixes #31458
2019-04-03 08:44:21 +00:00
Xavier Morel e36ad5b0b0 [FIX] core: handling of o2m record deletion in SSF
The SSF would properly mark its own records as deleted, but it would
not properly handle deletion requests coming from an onchange, and it
would not necessarily convert DELETE_ALL commands (5) into the proper
sequence of individual (2)s matching existing records.

closes odoo/odoo#31431
2019-02-26 13:18:57 +00:00
Xavier Morel bb7b121206 [FIX] core: various issues & deviations from client's behaviour in Form
* Form would entirely mis-interpret the server's response to some
  results: for unmodified o2m records the server sends a (4), which was
  un-interpreted by Form, leading to the o2m record being lost entirely
  (as it rebuilds the entire o2m on setting)
* on record creation, every field (except id) is considered modified not
  just the fields set by default_get
* Form diverged from actual client in that it would send (1, id, {}) for
  unmodified o2m records, actual client sends (4, id, False)
* datetimes should be sent stringified
* onchange should not be triggered when none of the modified fields is
  flagged as an onchange trigger
* the default value for numerical fields is 0 not False
* convert m2m onchange results to (6, False, ids) instead of (6, 0, ids)
  for ease of diffing with actual client's data

There are still a few odd divergences in the actual invocation of
onchange when attempted on an SO, but they look to be of low relevance
/ risk.

Note: making integer fields "required" has pretty much no effect
      anymore. This is in line with (my understanding of) the client's
      behaviour, but required the alteration of test models as the
      specific test on required... was using an integer field.

closes odoo/odoo#31064
2019-02-15 10:54:44 +00:00
Xavier Morel a313f342d3 [IMP] core: add force_save support to server-side form
Cf 3b3f6f04af for basic feature
description.

Task 1931580

closes odoo/odoo#30428
2019-01-22 11:12:39 +00:00
Laurent Smet 34c7fe2e77 [FIX] testing utilities: o2m should not strip readonly fields
In the normal course of saving-action, readonly fields are stripped
out when sending data to the server. The SSF would reuse the same code
when "saving" O2M lines to the parent record however that is not
correct and would lead to misbehaving views as readonly (non-stored)
fields used as "transients" (storing data within the extent of a
record's edition session) would not behave properly.

Fix by overriding the O2M Form's save so that readonly fields are
kept and stored in the parent record.

Closes #23620
2018-04-03 15:46:04 +02:00
xmo-odoo c385f5f418 [FIX] base: correctly handle non-normalised domains in SSF
Turns out I'd kinda skipped that bit.

Fixes #22711
2018-02-01 15:24:38 +01:00
Xavier Morel 4bf97bdbe2 [ADD] base: server-side formview
Useful to better test business flows & replace yaml test files:
instantiating records & calling onchanges by hand is very
error-prone (it's easy to miss onchanges, or to manually set fields
which can't be set through the view we're interested in, ...)

odoo.tests.common.Form implements the basic *creation*
flow (fields_get, default_get, onchange) up to saving the record,
including proper handling of the required and readonly modifiers &
their domains.

* edition of existing records, including filtering out unmodified
  fields when saving
* possibly buttons
* ensuring the API is convenient
2017-12-04 13:11:53 +01:00