[FIX] tests: allow False as value for required booleans in SSF
A required boolean accepts two values, True and False, however the SSF and the web-client assume False to be equal to NULL and treat them interchangeably. In the SSF, we verify that a required field is filled by checking that its value is different from False, however False is a valid value for a boolean, this means that setting a required boolean to False would never work in the SSF. This commit overcomes this issue by simply skipping the check for fields of type boolean. closes odoo/odoo#34729 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -19,3 +19,4 @@ access_model_test_testing_utilities_onchange_count,access_model_test_testing_uti
|
||||
access_test_testing_utilities_onchange_count_sub,access_test_testing_utilities_onchange_count_sub,model_test_testing_utilities_onchange_count_sub,,1,1,1,1
|
||||
access_o2m_readonly_subfield_parent,access_o2m_readonly_subfield_parent,model_o2m_readonly_subfield_parent,,1,1,1,1
|
||||
access_o2m_readonly_subfield_child,access_o2m_readonly_subfield_child,model_o2m_readonly_subfield_child,,1,1,1,1
|
||||
access_test_testing_utilities_req_bool,access_test_testing_utilities_req_bool,model_test_testing_utilities_req_bool,,1,0,0,0
|
||||
|
||||
|
@@ -261,3 +261,8 @@ class O2MReadonlySubfieldChild(models.Model):
|
||||
|
||||
def _inverse_f(self):
|
||||
raise AssertionError("Inverse of f should not be called")
|
||||
|
||||
class ReqBool(models.Model):
|
||||
_name = _description = 'test_testing_utilities.req_bool'
|
||||
|
||||
f_bool = fields.Boolean(required=True)
|
||||
|
||||
@@ -53,6 +53,16 @@ class TestBasic(TransactionCase):
|
||||
('1', 0, 0, 0)
|
||||
)
|
||||
|
||||
def test_required_bool(self):
|
||||
f = Form(self.env['test_testing_utilities.req_bool'])
|
||||
f.f_bool = False
|
||||
r = f.save()
|
||||
self.assertEqual(r.f_bool, 0)
|
||||
|
||||
f2 = Form(self.env['test_testing_utilities.req_bool'])
|
||||
r2 = f2.save()
|
||||
self.assertEqual(r2.f_bool, 0)
|
||||
|
||||
def test_readonly(self):
|
||||
"""
|
||||
Checks that fields with readonly modifiers (marked as readonly or
|
||||
|
||||
@@ -1385,7 +1385,7 @@ class Form(object):
|
||||
fields = self._view['fields']
|
||||
for f in fields:
|
||||
v = self._values[f]
|
||||
if self._get_modifier(f, 'required'):
|
||||
if self._get_modifier(f, 'required') and not fields[f]['type'] == 'boolean':
|
||||
assert v is not False, "{} is a required field".format(f)
|
||||
|
||||
# skip unmodified fields
|
||||
|
||||
Reference in New Issue
Block a user