How to resolve AssertionType error

fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2') >= 50 and ~Eval('fio_2') <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

On executing above code error showing up below:
File “/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py”, line 300, in init
‘statement must be an integer or a float’
AssertionError: statement must be an integer or a float

PYSON Eval uses the default value to determine the statement type. If no default value is set it uses an empty string. In your case the default value is a string (due to the empty string default value) which raises the AssertionError due to a comparision between char and integer.

You should specify a float default value for your code in order to resolve the ArrertionError. Something like:

fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2',0) >= 50 and ~Eval('fio_2',0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

Note that I’ve converted Eval('fio_2') into Eval('fio_2', 0)

Hope it helps!

1 Like

Sir, how will I specify a float default value for my code. Any guidance will be a great help.

Combine the word default and the field name into a function. Like:

fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2') >= 50 and ~Eval('fio_2') <= 100,
    }, depends=['fio_2'])


@staticmethod
def default_fio_2():
    return 40.0
1 Like

I think on Pyson you should use ‘&’ instead ‘and’

1 Like

I have coded the code like given below:

fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2', 0) >= 50 and ~Eval('fio_2', 0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')
@staticmethod
    def default_fio_2():
        return 0.0

But still the same error is coming:

File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 476, in <module>
    class PatientProfile(ModelSQL, ModelView):
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 742, in PatientProfile
    'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 67, in __ge__
    return Greater(self, other, True)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 301, in __init__
    'statement must be an integer or a float'
AssertionError: statement must be an integer or a float

Any further recommendation from your side will be helpful.

As @dabada83 said:

must use & instead of and like

'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100
1 Like

Sir, i have written the code like this, as follows:

fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

    @fields.depends('a_gradient')
    def on_change_with_a_gradient_point(self, name=None):
        result = 0
        if self.a_gradient in range(350, 500):
            result = 3
        elif self.a_gradient in range(200, 350):
            result = 2
        elif self.a_gradient in range(500, ):
            result = 4
        else:
            result = 0
        return result

    pao2 = fields.Integer('PaO2', states={
        'invisible': ~Eval('fio_2', 0) >= 0 & ~Eval('fio_2', 0) <= 49,
    }, depends=['fio_2'])
    pao2_point = fields.Function(
        fields.Integer('PaO2 Points', states={
            'invisible': ~Eval('pao2'),
        }, depends=['pao2']),
        'on_change_with_pao2_point')

    @fields.depends('pao2')
    def on_change_with_pao2_point(self, name=None):
        result = 0
        if self.pao2 in range(61, 71):
            result = 1
        elif self.pao2 in range(55, 61):
            result = 3
        else:
            result = 4
        return result

    @staticmethod
    def default_fio_2():
        return 0

On installing the module the error showing up as:

7602 140145196042048 [2020-01-27 07:28:37,148] INFO trytond.backend.postgresql.database connect to "anesticu"
Eval('id', 0)
7602 140145196042048 [2020-01-27 07:28:37,252] WARNING py.warnings /home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/wsgi.py:150: DeprecationWarning: 'werkzeug.wsgi.SharedDataMiddleware' has moved to 'werkzeug.middleware.shared_data.SharedDataMiddleware'. This import is deprecated as of version 0.15 and will be removed in version 1.0.
  app.wsgi_app = SharedDataMiddlewareIndex(app.wsgi_app, static_files)

7602 140145196042048 [2020-01-27 07:28:37,274] INFO trytond.modules ir:registering classes
7602 140145196042048 [2020-01-27 07:28:37,275] INFO trytond.modules res:registering classes
7602 140145196042048 [2020-01-27 07:28:37,275] INFO trytond.modules anaesthesiology_intensive_care:registering classes
Not(Bool(Eval('fio_2', 0)))
Traceback (most recent call last):
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 53, in import_module
    module = importlib.import_module(fullname)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'trytond.modules.anaesthesiology_intensive_care'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../../../../trytond/bin/trytond-admin", line 21, in <module>
    admin.run(options)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/admin.py", line 54, in run
    activatedeps=options.activatedeps)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pool.py", line 149, in init
    self.start()
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pool.py", line 102, in start
    register_classes()
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 331, in register_classes
    the_module = import_module(module)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/__init__.py", line 77, in import_module
    module = spec.loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/__init__.py", line 5, in <module>
    from .anaesthesiology_intensive_care import *
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 476, in <module>
    class PatientProfile(ModelSQL, ModelView):
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 742, in PatientProfile
    'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 67, in __ge__
    return Greater(self, other, True)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 301, in __init__
    'statement must be an integer or a float'
AssertionError: statement must be an integer or a float

Any further help will be highly appreciable.

Indeed ~ is equivalent to “not” so it is a Boolean expression type which can not be compared to integers.
So I guess you want:

'invisible': (Eval('fio_2', 0) < 50) & (Eval('fio_2', 0) > 100)

Check the parenthesis because they are required as & operator has binary operator has precedence over comparison operators.

1 Like

Thanks @ced sir, it worked.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.