Files
tryton/doc/ref/wizard.rst
T

209 lines
5.0 KiB
ReStructuredText
Raw Normal View History

2012-01-02 17:48:17 +01:00
.. _ref-wizard:
.. module:: trytond.wizard
======
Wizard
======
A wizard is a `finite state machine`_.
There is also a more :ref:`practical introduction into wizards
<topics-wizard>`.
.. _`finite state machine`: http://en.wikipedia.org/wiki/Finite-state_machine
2012-09-24 22:16:53 +02:00
.. class:: Wizard(session_id)
2012-01-02 17:48:17 +01:00
This is the base for any wizard. It contains the engine for the finite
state machine. A wizard must have some :class:`State` instance attributes
that the engine will use.
Class attributes are:
2012-09-24 22:16:53 +02:00
.. attribute:: Wizard.__name__
2012-01-02 17:48:17 +01:00
It contains the unique name to reference the wizard throughout the
platform.
.. attribute:: Wizard.start_state
It contains the name of the starting state.
.. attribute:: Wizard.end_state
It contains the name of the ending state.
2014-02-15 18:34:22 +01:00
If an instance method with this name exists on the wizard, it will be
called on deletion of the wizard and it may return one of the :ref:`client
side action keywords <topics-views-client-actions>`.
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
.. attribute:: Wizard.__rpc__
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
Same as :attr:`trytond.model.Model.__rpc__`.
2012-01-02 17:48:17 +01:00
.. attribute:: Wizard.states
It contains a dictionary with state name as key and :class:`State` as
value.
2012-09-24 22:16:53 +02:00
Class methods are:
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.__setup__()
Setup the class before adding into the :class:`trytond.pool.Pool`.
.. classmethod:: Wizard.__post_setup__()
Setup the class after added into the :class:`trytond.pool.Pool`.
.. classmethod:: Wizard.__register__(module_name)
2012-01-02 17:48:17 +01:00
Register the wizard.
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.create()
2012-01-02 17:48:17 +01:00
Create a session for the wizard and returns a tuple containing the session
id, the starting and ending state.
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.delete(session_id)
2012-01-02 17:48:17 +01:00
Delete the session.
2013-08-21 22:28:48 +02:00
.. classmethod:: Wizard.execute(session_id, data, state_name)
2012-01-02 17:48:17 +01:00
Execute the wizard for the state.
2013-08-21 22:28:48 +02:00
`session_id` is a session id.
2012-01-02 17:48:17 +01:00
`data` is a dictionary with the session data to update.
`active_id`, `active_ids`, `active_model` and `action_id` must be set in
the context according to the records on which the wizard is run.
2012-01-02 17:48:17 +01:00
=====
State
=====
.. class:: State()
This is the base for any wizard state.
2012-09-24 22:16:53 +02:00
Instance attributes are:
.. attribute:: State.name
The name of the state.
2012-01-02 17:48:17 +01:00
=========
StateView
=========
.. class:: StateView(model_name, view, buttons)
A :class:`StateView` is a state that will display a form in the client.
The form is defined by the :class:`~trytond.model.ModelView` with the name
`model_name`, the `XML` id in `view` and the `buttons`.
The default value of the view can be set with a method on wizard having the
same name as the state but starting with `default_`.
2012-01-02 17:48:17 +01:00
Instance attributes are:
.. attribute:: StateView.model_name
The name of the :class:`~trytond.model.ModelView`.
.. attribute:: StateView.view
The `XML` id of the form view.
.. attribute:: StateView.buttons
The list of :class:`Button` instances to display on the form.
Instance methods are:
.. method:: StateView.get_view(wizard, state_name)
2012-01-02 17:48:17 +01:00
Returns the view definition like
2012-08-23 14:02:36 +02:00
:meth:`~trytond.model.ModelView.fields_view_get`.
2012-01-02 17:48:17 +01:00
* wizard is a :class:`Wizard` instance
* state_name is the name of the :class:`StateView` instance
2013-08-21 22:28:48 +02:00
.. method:: StateView.get_defaults(wizard, state_name, fields)
2012-01-02 17:48:17 +01:00
Return default values for the fields.
* wizard is a :class:`Wizard` instance
* state_name is the name of the :class:`State`
* fields is the list of field names
.. method:: StateView.get_buttons(wizard, state_name)
Returns button definitions of the wizard.
* wizard is a :class:`Wizard` instance
* state_name is the name of the :class:`StateView` instance
===============
StateTransition
===============
.. class:: StateTransition()
A :class:`StateTransition` brings the wizard to the `state` returned by the
method having the same name as the state but starting with `transition_`.
===========
StateAction
===========
.. class:: StateAction(action_id)
A :class:`StateAction` is a :class:`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:
.. attribute:: StateAction.action_id
The `XML` id of the `ir.action`.
Instance methods are:
.. method:: StateAction.get_action()
Returns the `ir.action` definition.
2015-08-14 17:58:47 +02:00
===========
StateReport
===========
.. class:: StateReport(report_name)
A :class:`StateReport` is a :class:`StateAction` which find the report
action by name instead of `XML` id.
2012-01-02 17:48:17 +01:00
======
Button
======
.. class:: Button(string, state[, icon[, default]])
A :class:`Button` is a single object containing the definition of a wizard
button.
Instance attributes are:
.. attribute:: Button.string
The label display on the button.
.. attribute:: Button.state
The next state to reach if button is clicked.
.. attribute:: Button.icon
The name of the icon to display on the button.
.. attribute:: Button.default
A boolean to set it as default on the form.