Create one2many elements on a wizard

(Francisco Maria Moyano Casco) #1

Hi everyone,
I’m trying to make a wizard to import some data from a csv file.

I’m working on a 2 StateView wizard. The first one is used to choose the data file, the second one is used to have a preview of the data to be imported.

The issue is in the second StateView, when I try to fill a one2many field

The code used is like this:

class PartyPreview(ModelView):   
    __name__ = ''
    surname = fields.Char(
                    readonly = True

class PartyStateViewPreview(ModelView):
    'Patient StateView Preview'
    __name__ = ''
    party_list = fields.One2Many(
                            'Party Preview',
                            readonly = True

class PartyCreateWizard(Wizard):
    'Party Create'
    __name__ = ''
   #transition state between the first and the second StateView
   def transition_check_imported(self):
        # I know this is the wrong way, but I have no idea on how to make it work
        # when the one2many target to a ModelView class. 
        self.preview_data.party_list.append([{'surname': 'donatella'}])
       return 'preview_data'

   def default_preview_data(self,fields):
            'party_list': self.preview_data.party_list,

And have this trace

Traceback (most recent call last):
  File "/site-packages/trytond/model/", line 384, in __getattr__
    return self._values[name]
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/site-packages/trytond/", line 70, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/site-packages/trytond/protocols/", line 41, in rpc
    request, database_name, *request.rpc_params)
  File "/site-packages/trytond/", line 41, in auth_required
    return wrapped(*args, **kwargs)
  File "/site-packages/trytond/protocols/", line 110, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/site-packages/trytond/protocols/", line 165, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/site-packages/trytond/wizard/", line 287, in execute
    return wizard._execute(state_name)
  File "/site-packages/trytond/wizard/", line 318, in _execute
    result = self._execute(transition())
  File "/site-packages/trytond/modules/health/wizard/", line 88, in transition_check_imported
    self.preview_data.party_list.append([{'surname': 'donatella'}])
  File "/site-packages/trytond/model/", line 387, in __getattr__
    % (self.__name__, name, self._values))
AttributeError: '' Model has no attribute 'party_list': None

Any idea on how to make it work? Is there any modules that makes something similar?


(Cédric Krier) #2

You can not set data on a StateView that was not yet displayed.
Indeed you must only rely on the default value method and use the data from the previous StateView for example.

(Francisco Maria Moyano Casco) #3

Thank you @ced for the quickly answer, and thank you @nicoe for editing and formating my post
Actually, I use the default_preview_data method, and that works
Again, thanks