Wizard

A wizard is a finite state machine.

There is also a more practical introduction into wizards.

class trytond.wizard.Wizard

This is the base for any wizard. It contains the engine for the finite state machine. A wizard must have some State instance attributes that the engine will use.

Class attributes are:

Wizard._name

It contains the unique name to reference the wizard throughout the platform.

Wizard.start_state

It contains the name of the starting state.

Wizard.end_state

It contains the name of the ending state.

Wizard._rpc

Same as trytond.model.Model._rpc.

Wizard.states

It contains a dictionary with state name as key and State as value.

Instance methods are:

Wizard.init(module_name)

Register the wizard.

Wizard.create()

Create a session for the wizard and returns a tuple containing the session id, the starting and ending state.

Wizard.delete(session_id)

Delete the session.

Wizard.execute(session, data, state_name)

Execute the wizard for the state. session can be an instance of Session or a session id. data is a dictionary with the session data to update. active_id, active_ids and active_model must be set in the context according to the records on which the wizard is run.

Session

class trytond.wizard.Session(wizard, session_id)

A wizard session contains values of each StateView associated to the wizard.

Instance attributes are:

Session.data

Raw storage of session data.

Instance methods are:

Session.save()

Save the session in database.

State

class trytond.wizard.State

This is the base for any wizard state.

StateView

class trytond.wizard.StateView(model_name, view, buttons)

A StateView is a state that will display a form in the client. The form is defined by the ModelView with the name model_name, the XML id in view and the buttons.

Instance attributes are:

StateView.model_name

The name of the ModelView.

StateView.view

The XML id of the form view.

StateView.buttons

The list of Button instances to display on the form.

Instance methods are:

StateView.get_view()

Returns the view definition like fields_view_get().

StateView.get_defaults(wizard, session, state_name, fields)

Return default values for the fields.

  • wizard is a Wizard instance
  • session is a Session instance
  • state_name is the name of the State
  • fields is the list of field names
StateView.get_buttons(wizard, state_name)

Returns button definitions of the wizard.

  • wizard is a Wizard instance
  • state_name is the name of the StateView instance

StateTransition

class trytond.wizard.StateTransition

A StateTransition brings the wizard to the state returned by the method having the same name as the state but starting with transition_.

StateAction

class trytond.wizard.StateAction(action_id)

A StateAction is a StateTransition which let the client launch an ir.action. This action definition can be customized with a method on wizard having the same name as the state but starting with do_.

Instance attributes are:

StateAction.action_id

The XML id of the ir.action.

Instance methods are:

StateAction.get_action()

Returns the ir.action definition.

Button

class trytond.wizard.Button(string, state[, icon[, default]])

A Button is a single object containing the definition of a wizard button.

Instance attributes are:

Button.string

The label display on the button.

Button.state

The next state to reach if button is clicked.

Button.icon

The name of the icon to display on the button.

Button.default

A boolean to set it as default on the form.

Table Of Contents

Previous topic

Fields

Next topic

PYSON

This Page