[FIX] tests: correctly handle invisible fields in form proxy

The form proxy will raise an error if a required field is not filled,
even when the web client would let it pass through. Indeed, the web
client (correctly) assumes that a user cannot fill in an invisible
field and that something will probably be done on the server to handle
that (e.g. an override of the write/create or simply a command-handling
code by the ORM). Since invisible fields do not even get a widget
instaciated for them, no validation takes place whatsoever.

Since it is sometimes (for obscure reasons) necessary to include all
kinds of invisible fields in tree view (e.g. to get correct values for
related stored fields, somehow), it is possible that required fields
in a view are in fact not really required since they are ignored
by the web client and then correctly handled/modified server-side.

This commit adapts the test proxies to behave similarly to the web client
(since that is, after all, the goal of these proxies) and to ignore
invisible fields when validating views.

closes odoo/odoo#37432

Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
Damien Bouvy
2019-09-30 16:20:51 +00:00
parent b32132973c
commit 652ebb96e5
+2 -2
View File
@@ -1539,7 +1539,7 @@ class Form(object):
for f in fields:
descr = fields[f]
v = self._values[f]
if self._get_modifier(f, 'required') and not descr['type'] == 'boolean':
if self._get_modifier(f, 'required') and not (descr['type'] == 'boolean' or self._get_modifier(f, 'invisible')):
assert v is not False, "{} is a required field".format(f)
# skip unmodified fields
@@ -1764,7 +1764,7 @@ class O2MForm(Form):
values._changed.update(self._changed)
for f in self._view['fields']:
if self._get_modifier(f, 'required'):
if self._get_modifier(f, 'required') and not (self._get_modifier(f, 'column_invisible') or self._get_modifier(f, 'invisible')):
assert self._values[f] is not False, "{} is a required field".format(f)
return values