How to take the existing values in the content of the fields of a record when implementing a Wizard?
Previously we received help to save the records. Our query now, is a little different.
PURPOSE:
To develop a Wizard that allows to use the existing current values in the fields of a record.
THE EXPECTED
It is expected that the wizard will be able to call the values of the fields of a record and manage to update them.
DIFFICULTY:
We have our ‘incidents’ model with records that we want to update.
It has been tried with two methods: Pool(), Transaction().
(Please see the example codes)
- With the Pool method, we are not able to take the values of incident.observations
- With the Transaction().context.get( ‘observations’) method we are not successful either.
Both methods generate error.
ENVIRONMENT:
- OS: Ubuntu 20.04.1 LTS
- Python: 3.8.5
- Trytond: 5.8.1
- Tryton: 5.8.1
- Module: 5.8
- Postgresql: 12.5
EXAMPLE CODE:
start_state = 'parameters'
parameters = StateView(
'incidents.solve_incidents.parameters',
'incidents.solve_incidents_parameters_view_form', [
Button('Cancelar', 'end', 'tryton-cancel'),
Button('Resolver', 'solve', 'solve', default=True)
])
solve = StateTransition()
open_incidents = StateAction('incidents.act_state_resolved_list')
Option with the Pool() method
def default_parameters(self, name):
pool = Pool()
Incident = pool.get('incidents')
incidents = Incident.browse(Transaction().context['active_ids'])
for incident in incidents:
self.parameters.observations = incident.observations
Option with the Transaction() method
def default_parameters(self, name):
self.parameters.observations = Transaction().context.get(
'observations')
The rest of the code stores the record. It works well.
def transition_block(self):
pool = Pool()
Incident = pool.get('incidents')
incidents = Incident.browse(Transaction().context['active_ids'])
for incident in incidents:
incident.observations = self.parameters.observations
incident.sub_state = self.parameters.sub_state
Incident.save(incidents)
return 'end'
ERROR MESSAGE:
Error with Pool() method
Traceback (most recent call last):
File "/trytond/wsgi.py", line 111, in dispatch_request
return endpoint(request, **request.view_args)
File "/trytond/protocols/dispatcher.py", line 47, in rpc
return methods.get(request.rpc_method, _dispatch)(
File "/trytond/wsgi.py", line 78, in auth_required
return wrapped(*args, **kwargs)
File "/trytond/protocols/wrappers.py", line 131, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 181, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/wizard/wizard.py", line 314, in execute
return wizard._execute(state_name)
File "/trytond/wizard/wizard.py", line 325, in _execute
defaults = state.get_defaults(self, state_name,
File "/trytond/wizard/wizard.py", line 95, in get_defaults
defaults.update(default(fields))
TypeError: 'NoneType' object is not iterable
Fault: 'NoneType' object is not iterable
Error with Transaction() method
Traceback (most recent call last):
File "/trytond/wsgi.py", line 111, in dispatch_request
return endpoint(request, **request.view_args)
File "/trytond/protocols/dispatcher.py", line 47, in rpc
return methods.get(request.rpc_method, _dispatch)(
File "/trytond/wsgi.py", line 78, in auth_required
return wrapped(*args, **kwargs)
File "/trytond/protocols/wrappers.py", line 131, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 181, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/wizard/wizard.py", line 314, in execute
return wizard._execute(state_name)
File "/trytond/wizard/wizard.py", line 325, in _execute
defaults = state.get_defaults(self, state_name,
File "/trytond/wizard/wizard.py", line 95, in get_defaults
defaults.update(default(fields))
TypeError: 'NoneType' object is not iterable
Fault: 'NoneType' object is not iterable
We thank you for your guidance in implementing it in the right way.
happy holidays!