List on a wizard stateview

Hi,
I am having some issues using tryton 4.6 module on tryton 5.0
The issue is with a One2Many list based on a ModelView class.
I tried to scrap an example of the code, so I don’t have to copy all the original.
The idea behind is to fullfill a list (the one2many) with something.

class Element(ModelView):
   'Element'
    __name__ = 'list.element'

    foo = fields.Char("Foo")

class ListElement(ModelView):
    'List Element'
    __name__ = 'list.list'

    elements = fields.One2Many('list.element',None,'Cobertura',
        readonly=True)

class MyWizard(Wizard):
    'The wiz'
    __name__ = 'fill.list'

    start = 'start'
    start = StateView(....)
    check_existence = StateTransition()
    found = StateView(....) # asociated to a view related to ListElement model
    not_found = StateView(....)
    show_results = StateAction(....)

    def transition_check_existence(self):
        Party = Pool().get('party.party')
        (.....)
        parties = Party.search(something)
        names = []
        if parties:
            name = [x.name for x in parties]
            self.found.names = names
            return 'found'
        return 'not found'
    
    def default_found(self):
        elements = []
        element = {}
        for name in self.found.names:
            element['name'] = name
            elements.append(name)
            element = {}
        return{
                'elements': elements,
                }
            
    def do_show_results(self):
        (...)

When I try to run the wizard, it’s ok on the start state, but in the found state gives me this error:

File "/home/fran/.local/lib/python3.6/site-packages/tryton/common/common.py", line 999, in process
    self.callback(return_)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/wizard.py", line 108, in callback
    self.update(view['fields_view'], view['buttons'])
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/wizard.py", line 361, in update
    super(WizardDialog, self).update(view, buttons)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/wizard.py", line 202, in update
    self.screen.add_view(view)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 581, in add_view
    self, view_id, view['type'], xml_dom, view.get('field_childs'))
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 74, in parse
    return ViewForm(view_id, screen, root)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 413, in __init__
    super().__init__(view_id, screen, xml)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 35, in __init__
    ).parse(xml)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 196, in _parse_form
    self.parse_child(node, container)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 203, in parse_child
    self.parse(child)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 341, in _parse_group
    self.parse_child(node, group)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 203, in parse_child
    self.parse(child)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 341, in _parse_group
    self.parse_child(node, group)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 203, in parse_child
    self.parse(child)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form.py", line 213, in _parse_field
    widget = self.WIDGETS[attributes['widget']](self.view, attributes)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/form_gtk/one2many.py", line 165, in __init__
    limit=None)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 139, in __init__
    self.switch_view()
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 514, in switch_view
    self.load_view_to_load()
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 540, in load_view_to_load
    self.add_view_id(view_id, view_type)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 553, in add_view_id
    return self.add_view(view)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/screen/screen.py", line 581, in add_view
    self, view_id, view['type'], xml_dom, view.get('field_childs'))
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 72, in parse
    return ViewTree(view_id, screen, root, children_field)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/list.py", line 451, in __init__
    super().__init__(view_id, screen, xml)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 35, in __init__
    ).parse(xml)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/list.py", line 287, in _parse_tree
    self.parse(child)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/__init__.py", line 130, in parse
    parser(node, node_attrs)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/list.py", line 291, in _parse_field
    widget = self.WIDGETS[attributes['widget']](self.view, attributes)
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/gui/window/view_form/view/list_gtk/widget.py", line 932, in __init__
    self.init_selection()
  File "/home/fran/.local/lib/python3.6/site-packages/tryton/common/selection.py", line 43, in init_selection
    selection.sort(key=operator.itemgetter(1))

TypeError: '<' not supported between instances of 'str' and 'NoneType'

Thanks in advance

This is not supported. You must use always the same series.

Yes, I know. It’s a module from my own.

I’m trying to migrate the code from 4.6 to 5.0. I found what lines are the ones wich cause the error, but I can’t interpret the error log.
Apparently, it’s trying to order the one2many list trough an inexistent field (the "`
TypeError: ‘<’ not supported between instances of ‘str’ and ‘NoneType’ " line on the error log).

Don’t know why, but in this series it doesn’t work as it did it on the others.

This is an error raised on python3 when comparing None to a string. On python2 this did not cause any error.

For example (on python2):

>>> '' < None
False

but on python3:

>>> '' < None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'NoneType'

Probably removing the non existent field from the order will solve the issue.

Nice. We are getting closer then.
The question itself will be wich field is that one.

Changing the one2many target to a ModelSQL class (party.party), it gives me no error. Could it be possible that using a ModelView class is the origin of that error? Is there any tip/hint to solve this?

Thanks

If you use a ModelView you should use None as target of the relation.

Indeed, I am using a None as the field of the model target (see the example code)

So probably there is an error on the model definition or something else.

I’m sorry but without the full code I can not provide more advices.

You can not use One2Many with None on a wizard, you must use a Many2Many with a couple of None’s.
But the error is not about that but about a selection widget that is used with values having None as string.

What does the server-side say? You have now only given the error on the client-side.

This was the answer!!! Every answer get me closer and closer to the final solution.

I did a mistake on one fields.Selection.
I put a tuple like (’’, None) instead of (None, ‘’).

Like pokoli saids, the code works fine on python2, but returns an error on python3

And like cedric saids, it was about a selection field.

Thank you all!

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