Dear Tryton Community,
How to Update Records with Wizard?
Trying to make our first Wizard.
We have a model to which we want to update data using Wizard.
The model contains several fields, the records were written in another form.
The Wizard is required to manage the records.
The Wizard is invoked from a button called from a form which contains an existing record.
The Wizard creates a new form with a field to enter information (type: fields…Text) and with two buttons called and .
It is expected that a click on the “save” button will save the form data in the model of the existing record.
Difficulty:
- Clicking the “save” button in the Wizard does not save the records.
- How to write correctly the call code of the record fields?
Error:
- The function write() is not receiving the necessary parameters.
TypeError: write() missing 1 required positional argument: 'values
- When we replace the write() function with the save() function, it lets the parameters pass, but requests fields from the existing record, previously entered
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
CODE:
Please check our wizard code:
class wizard(Wizard):
'Wizard'
__name__ = 'wizard'
start_state = 'parameters'
parameters = StateView(
'model.name.parameters',
'model.name_view_form', [
Button('Cancelar', 'end', 'tryton-cancel'),
Button('Guardar', 'save', 'tryton-forward', default=True)
])
save = StateTransition()
open_incidents = StateAction('model.act_name_list')
def default_parameters(self, name):
Model = Pool().get('model_name')
model = Model.browse(Transaction().context.get('active_id')) # extraer el modelo
return model, {
'field_date': datetime.datetime.today(),
'field_state': 'closed',
'field_sub_state': 'new_closed',
} # Valores del formulario del wizard que se van a actualizar en el registro
def transition_save(self, model):
to_update = []
field_date = self.parameters.field_date
field_summary = self.parameters.field_summary
state = self.parameters.field_state
sub_state = self.parameters.field_sub_state
to_update.append(
model(field_date=field_date,
field_summary=field_summary,
field_state=state,
field_sub_state=sub_state,
))
model.write(to_update)
return 'end'
class parameters (ModelView):
‘Parameters’
__name__ = ‘wizard.parameters’
field_summary = fields.Text
field_date = fields.DateTime
field_state = fields.Selection
field_sub_state = fields.Selection
We are just recognizing this wonderful Tryton.
Appreciate all your valuable help !!
Any comment welcome.