Files
tryton/trytond/doc/ref/wizard.rst
T

257 lines
5.9 KiB
ReStructuredText
Raw Normal View History

2012-01-02 17:48:17 +01:00
.. _ref-wizard:
.. module:: trytond.wizard
2022-03-27 16:06:09 +02:00
2012-01-02 17:48:17 +01:00
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
2022-03-27 16:06:09 +02: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
uses.
2012-01-02 17:48:17 +01:00
Class attributes are:
2012-09-24 22:16:53 +02:00
.. attribute:: Wizard.__name__
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
The unique name to reference the wizard throughout the platform.
2012-01-02 17:48:17 +01:00
.. attribute:: Wizard.start_state
2022-03-27 16:06:09 +02:00
The name of the starting state.
2012-01-02 17:48:17 +01:00
.. attribute:: Wizard.end_state
2022-03-27 16:06:09 +02:00
The name of the ending state.
If an instance method with this name exists on the wizard, it is 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
2022-03-27 16:06:09 +02:00
Same as :attr:`trytond.model.Model.__rpc__`.
2012-01-02 17:48:17 +01:00
.. attribute:: Wizard.states
2022-03-27 16:06:09 +02:00
A dictionary with state name as key and :class:`State` as value.
2012-01-02 17:48:17 +01:00
.. attribute:: model
2022-03-27 16:06:09 +02:00
The :class:`~trytond.model.Model` class on which the wizard is executed.
.. attribute:: record
2022-03-27 16:06:09 +02:00
The :class:`~trytond.model.Model` instance on which the wizard is executed.
.. attribute:: records
2022-03-27 16:06:09 +02:00
The list of :class:`~trytond.model.Model` instances on which the wizard is
executed.
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__()
2022-03-27 16:06:09 +02:00
Setup the class before adding into the :class:`~trytond.pool.Pool`.
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.__post_setup__()
2022-03-27 16:06:09 +02:00
Setup the class after added into the :class:`~trytond.pool.Pool`.
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.__register__(module_name)
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Register the wizard.
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.create()
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Create a session for the wizard and returns a tuple containing the session
id, the starting and ending state.
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
.. classmethod:: Wizard.delete(session_id)
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Delete the session.
2012-01-02 17:48:17 +01:00
2013-08-21 22:28:48 +02:00
.. classmethod:: Wizard.execute(session_id, data, state_name)
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Execute the wizard for the state.
``session_id`` is a session id.
``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
2022-03-27 16:06:09 +02:00
-----
2012-01-02 17:48:17 +01:00
.. class:: State()
2022-03-27 16:06:09 +02:00
The base for any wizard state.
2012-01-02 17:48:17 +01:00
2012-09-24 22:16:53 +02:00
Instance attributes are:
.. attribute:: State.name
2022-03-27 16:06:09 +02:00
The name of the state.
2012-09-24 22:16:53 +02:00
2012-01-02 17:48:17 +01:00
StateView
2022-03-27 16:06:09 +02:00
---------
2012-01-02 17:48:17 +01:00
.. class:: StateView(model_name, view, buttons)
2022-03-27 16:06:09 +02:00
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``.
2022-10-01 14:45:59 +02:00
The default values of the view can be set with a method on wizard having the
2022-03-27 16:06:09 +02:00
same name as the state but starting with ``default_``.
2022-10-01 14:45:59 +02:00
The values of the view can be also set with a method on wizard having the
same name as the state but starting with ``value_``.
.. note::
The difference between default values and values is that the client calls
:meth:`~trytond.model.ModelView.on_change` and
:meth:`~trytond.model.ModelView.on_change_with` for the default values.
2012-01-02 17:48:17 +01:00
Instance attributes are:
.. attribute:: StateView.model_name
2022-03-27 16:06:09 +02:00
The name of the :class:`~trytond.model.ModelView`.
2012-01-02 17:48:17 +01:00
.. attribute:: StateView.view
2022-03-27 16:06:09 +02:00
The XML id of the form view.
2012-01-02 17:48:17 +01:00
.. attribute:: StateView.buttons
2022-03-27 16:06:09 +02:00
The list of :class:`Button` instances to display on the form.
2012-01-02 17:48:17 +01:00
Instance methods are:
.. method:: StateView.get_view(wizard, state_name)
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Return the view definition like
:meth:`~trytond.model.ModelView.fields_view_get`.
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02: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
2022-03-27 16:06:09 +02:00
Return default values for the fields.
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
``wizard`` is a :class:`Wizard` instance.
``state_name`` is the name of the :class:`State`.
``fields`` is the list of field names.
2012-01-02 17:48:17 +01:00
2022-10-01 14:45:59 +02:00
.. method:: StateView.get_values(wizard, state_name, fields)
Return 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.
2012-01-02 17:48:17 +01:00
.. method:: StateView.get_buttons(wizard, state_name)
2022-03-27 16:06:09 +02:00
Return button definitions of the wizard.
``wizard`` is a :class:`Wizard` instance.
``state_name`` is the name of the :class:`StateView` instance.
2012-01-02 17:48:17 +01:00
StateTransition
2022-03-27 16:06:09 +02:00
---------------
2012-01-02 17:48:17 +01:00
.. class:: StateTransition()
2022-03-27 16:06:09 +02:00
A :class:`StateTransition` brings the wizard to the ``state`` returned by
the method having the same name as the state but starting with
``transition_``.
2012-01-02 17:48:17 +01:00
StateAction
2022-03-27 16:06:09 +02:00
-----------
2012-01-02 17:48:17 +01:00
.. class:: StateAction(action_id)
2022-03-27 16:06:09 +02:00
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_``.
2012-01-02 17:48:17 +01:00
Instance attributes are:
.. attribute:: StateAction.action_id
2022-03-27 16:06:09 +02:00
The XML id of the ``ir.action``.
2012-01-02 17:48:17 +01:00
Instance methods are:
.. method:: StateAction.get_action()
2022-03-27 16:06:09 +02:00
Return the ``ir.action`` definition.
2012-01-02 17:48:17 +01:00
2015-08-14 17:58:47 +02:00
StateReport
2022-03-27 16:06:09 +02:00
-----------
2015-08-14 17:58:47 +02:00
.. class:: StateReport(report_name)
2022-03-27 16:06:09 +02:00
A :class:`StateAction` which find the report action by name instead of XML
id.
2015-08-14 17:58:47 +02:00
2012-01-02 17:48:17 +01:00
Button
2022-03-27 16:06:09 +02:00
------
2012-01-02 17:48:17 +01:00
2019-11-21 15:39:56 +01:00
.. class:: Button(string, state[, icon[, default[, validate]]])
2012-01-02 17:48:17 +01:00
2022-03-27 16:06:09 +02:00
Define of a wizard button.
2012-01-02 17:48:17 +01:00
Instance attributes are:
.. attribute:: Button.string
2022-03-27 16:06:09 +02:00
The label display on the button.
2012-01-02 17:48:17 +01:00
.. attribute:: Button.state
2022-03-27 16:06:09 +02:00
The next state to reach if button is clicked.
2012-01-02 17:48:17 +01:00
.. attribute:: Button.icon
2022-03-27 16:06:09 +02:00
The name of the icon to display on the button.
2012-01-02 17:48:17 +01:00
.. attribute:: Button.default
2022-03-27 16:06:09 +02:00
A boolean to set it as default on the form.
2019-11-21 15:39:56 +01:00
.. attribute:: Button.validate
A boolean or None.
2022-03-27 16:06:09 +02:00
If ``True``, validation of the form will occur, if ``False`` it won't.
If the value is ``None`` the validation will occur only if the state of the
button is not the wizard ending state.