diff --git a/multi_step_wizard/README.rst b/multi_step_wizard/README.rst new file mode 100644 index 0000000000..566fa0d9dd --- /dev/null +++ b/multi_step_wizard/README.rst @@ -0,0 +1,175 @@ +=================== +Multi-Steps Wizards +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:60da2ae2647bd104667af695a6ab276dbddb348c878d83605a6617dc66b3c28f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/18.0/multi_step_wizard + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-18-0/server-ux-18-0-multi_step_wizard + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is a base for creating multi-steps wizards. It does nothing +by itself. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Example of class: + +.. code:: python + + class MyWizard(models.TransientModel): + _name = 'my.wizard' + _inherit = ['multi.step.wizard.mixin'] + + project_id = fields.Many2one( + comodel_name='project.project', + name="Project", + required=True, + ondelete='cascade', + default=lambda self: self._default_project_id(), + ) + name = fields.Char() + field1 = fields.Char() + field2 = fields.Char() + field3 = fields.Char() + + @api.model + def _selection_state(self): + return [ + ('start', 'Start'), + ('configure', 'Configure'), + ('custom', 'Customize'), + ('final', 'Final'), + ] + + @api.model + def _default_project_id(self): + return self.env.context.get('active_id') + + def state_exit_start(self): + self.state = 'configure' + + def state_exit_configure(self): + self.state = 'custom' + + def state_exit_custom(self): + self.state = 'final' + +Example of view (note the mode, must be primary): + +.. code:: xml + + + + + + my.wizard.form + my.wizard + primary + + + +

+ +

+ + + + + + + + + + + +
+

The project is now configured.

+
+
+
+
+ + + My Wizard + my.wizard + form + new + + form + +
+ +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Guewen Baconnier +- `CorporateHub `__ + + - Alexey Pelykh + +- Sunanda Chhatbar + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/multi_step_wizard/__init__.py b/multi_step_wizard/__init__.py new file mode 100644 index 0000000000..4b76c7b2d5 --- /dev/null +++ b/multi_step_wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/multi_step_wizard/__manifest__.py b/multi_step_wizard/__manifest__.py new file mode 100644 index 0000000000..7b4a530570 --- /dev/null +++ b/multi_step_wizard/__manifest__.py @@ -0,0 +1,12 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Multi-Steps Wizards", + "version": "18.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["base"], + "website": "https://github.com/OCA/server-ux", + "data": ["views/multi_step_wizard_views.xml"], + "installable": True, +} diff --git a/multi_step_wizard/i18n/ca.po b/multi_step_wizard/i18n/ca.po new file mode 100644 index 0000000000..46fb81d6d5 --- /dev/null +++ b/multi_step_wizard/i18n/ca.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-01-26 18:52+0000\n" +"Last-Translator: Jaume Planas \n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "Permet enrera" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Cancel·la" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "Enrera" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "Mixin Assistent multipas" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Següent" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Estat" + +#~ msgid "Display Name" +#~ msgstr "nOM" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificació el" diff --git a/multi_step_wizard/i18n/de.po b/multi_step_wizard/i18n/de.po new file mode 100644 index 0000000000..d4757242d8 --- /dev/null +++ b/multi_step_wizard/i18n/de.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-01 08:31+0000\n" +"Last-Translator: John Herholz \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "Zurück erlauben" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Abbrechen" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "Zurück" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "Mehrstufiger Assistent Mixin" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Weiter" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Status" diff --git a/multi_step_wizard/i18n/es.po b/multi_step_wizard/i18n/es.po new file mode 100644 index 0000000000..8c8a4c5d58 --- /dev/null +++ b/multi_step_wizard/i18n/es.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-11 15:33+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "Permitir Volver" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Cancelar" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "Volver" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "Mezclador Asistente de Pasos Múltiples" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Siguiente" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Estado" diff --git a/multi_step_wizard/i18n/hr.po b/multi_step_wizard/i18n/hr.po new file mode 100644 index 0000000000..ec3f367898 --- /dev/null +++ b/multi_step_wizard/i18n/hr.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-12-04 12:04+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 3.9.1\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Odustani" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "Multi Steps Wizard Mixin" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Sljedeći" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Status" + +#~ msgid "Created by" +#~ msgstr "Kreirao" + +#~ msgid "Created on" +#~ msgstr "Kreirano" + +#~ msgid "Display Name" +#~ msgstr "Naziv" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Zadnje modificirano" + +#~ msgid "Last Updated by" +#~ msgstr "Zadnje ažurirao" + +#~ msgid "Last Updated on" +#~ msgstr "Zadnje ažurirano" + +#~ msgid "Multi Step Wizard Test" +#~ msgstr "Čarobnjak sa više koraka Test" + +#~ msgid "Close" +#~ msgstr "Zatvori" diff --git a/multi_step_wizard/i18n/it.po b/multi_step_wizard/i18n/it.po new file mode 100644 index 0000000000..ca947a4667 --- /dev/null +++ b/multi_step_wizard/i18n/it.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-31 19:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "Consenti indietro" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Annulla" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "Indietro" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "Mixin procedura guidata passi multipli" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Successivo" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Stato" diff --git a/multi_step_wizard/i18n/multi_step_wizard.pot b/multi_step_wizard/i18n/multi_step_wizard.pot new file mode 100644 index 0000000000..6ef7a0a58d --- /dev/null +++ b/multi_step_wizard/i18n/multi_step_wizard.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "" diff --git a/multi_step_wizard/i18n/nl.po b/multi_step_wizard/i18n/nl.po new file mode 100644 index 0000000000..ddad88558d --- /dev/null +++ b/multi_step_wizard/i18n/nl.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-11-25 14:51+0000\n" +"Last-Translator: Dennis Sluijk \n" +"Language-Team: none\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "Teruggaan Toelaten" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "Annuleer" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "Ga Terug" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "Volgende" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "Status" + +#~ msgid "Created by" +#~ msgstr "Aangemaakt door" + +#~ msgid "Created on" +#~ msgstr "Aangemaakt op" + +#~ msgid "Display Name" +#~ msgstr "Schermnaam" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Laatst gewijzigd op" + +#~ msgid "Last Updated by" +#~ msgstr "Laatst bijgewerkt door" + +#~ msgid "Last Updated on" +#~ msgstr "Laatst bijgewerkt op" diff --git a/multi_step_wizard/i18n/zh_CN.po b/multi_step_wizard/i18n/zh_CN.po new file mode 100644 index 0000000000..ea55a4a7cf --- /dev/null +++ b/multi_step_wizard/i18n/zh_CN.po @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * multi_step_wizard +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-09-02 16:57+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__allow_back +msgid "Allow Back" +msgstr "" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Cancel" +msgstr "取消" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Go Back" +msgstr "" + +#. module: multi_step_wizard +#: model:ir.model,name:multi_step_wizard.model_multi_step_wizard_mixin +msgid "Multi Steps Wizard Mixin" +msgstr "多步骤向导混合" + +#. module: multi_step_wizard +#: model_terms:ir.ui.view,arch_db:multi_step_wizard.multi_step_wizard_form +msgid "Next" +msgstr "下一个" + +#. module: multi_step_wizard +#: model:ir.model.fields,field_description:multi_step_wizard.field_multi_step_wizard_mixin__state +msgid "State" +msgstr "状态" + +#~ msgid "Created by" +#~ msgstr "创建者" + +#~ msgid "Created on" +#~ msgstr "创建时间" + +#~ msgid "Display Name" +#~ msgstr "显示名称" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "最后修改时间" + +#~ msgid "Last Updated by" +#~ msgstr "最后更新者" + +#~ msgid "Last Updated on" +#~ msgstr "最后更新时间" + +#~ msgid "Multi Step Wizard Test" +#~ msgstr "多步骤向导测试" + +#~ msgid "Close" +#~ msgstr "关闭" diff --git a/multi_step_wizard/models/__init__.py b/multi_step_wizard/models/__init__.py new file mode 100644 index 0000000000..28c1e4fa04 --- /dev/null +++ b/multi_step_wizard/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import multi_step_wizard diff --git a/multi_step_wizard/models/multi_step_wizard.py b/multi_step_wizard/models/multi_step_wizard.py new file mode 100644 index 0000000000..72be7bb1b1 --- /dev/null +++ b/multi_step_wizard/models/multi_step_wizard.py @@ -0,0 +1,76 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + + +class MultiStepWizard(models.AbstractModel): + """Mixin to ease the creation of multisteps wizards + + _selection_state must return all possible step of + the wizard. + + For each state but final, there must be a method named + "state_exit_X" where X is the name of the state. Each + of these method must set the next state in self.state. + + For each state but start, there may be a method named + "state_previous_X" where X is the name of the state. Each + of these method must set the next state in self.state. + + The final state has no related method because the view + should only display a button to close the wizard. + + open_next, open_previous and _reopen_self should not need to be + overidden, but _selection_state and state_exit_start + likely will need to. + + """ + + _name = "multi.step.wizard.mixin" + _description = "Multi Steps Wizard Mixin" + + state = fields.Selection( + selection="_selection_state", default="start", required=True + ) + + allow_back = fields.Boolean(compute="_compute_allow_back") + + @api.depends("state") + def _compute_allow_back(self): + for record in self: + record.allow_back = getattr(record, f"state_previous_{record.state}", False) + + @api.model + def _selection_state(self): + return [("start", "Start"), ("final", "Final")] + + def open_next(self): + state_method = getattr(self, f"state_exit_{self.state}", None) + if state_method is None: + raise NotImplementedError(f"No method defined for state {self.state}") + state_method() + return self._reopen_self() + + def open_previous(self): + state_method = getattr(self, f"state_previous_{self.state}", None) + if state_method is None: + raise NotImplementedError(f"No method defined for state {self.state}") + state_method() + return self._reopen_self() + + def _reopen_self(self): + return { + "type": "ir.actions.act_window", + "res_model": self._name, + "res_id": self.id, + "view_mode": "form", + "target": "new", + } + + def state_exit_start(self): + self.state = "final" diff --git a/multi_step_wizard/pyproject.toml b/multi_step_wizard/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/multi_step_wizard/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/multi_step_wizard/readme/CONTRIBUTORS.md b/multi_step_wizard/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ad31c300a0 --- /dev/null +++ b/multi_step_wizard/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Guewen Baconnier \<\> +- [CorporateHub](https://corporatehub.eu/) + - Alexey Pelykh \<\> +- Sunanda Chhatbar \<\> diff --git a/multi_step_wizard/readme/DESCRIPTION.md b/multi_step_wizard/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f09b84d6ed --- /dev/null +++ b/multi_step_wizard/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module is a base for creating multi-steps wizards. It does nothing +by itself. diff --git a/multi_step_wizard/readme/USAGE.md b/multi_step_wizard/readme/USAGE.md new file mode 100644 index 0000000000..7a377c6358 --- /dev/null +++ b/multi_step_wizard/readme/USAGE.md @@ -0,0 +1,89 @@ +Example of class: + +``` python +class MyWizard(models.TransientModel): + _name = 'my.wizard' + _inherit = ['multi.step.wizard.mixin'] + + project_id = fields.Many2one( + comodel_name='project.project', + name="Project", + required=True, + ondelete='cascade', + default=lambda self: self._default_project_id(), + ) + name = fields.Char() + field1 = fields.Char() + field2 = fields.Char() + field3 = fields.Char() + + @api.model + def _selection_state(self): + return [ + ('start', 'Start'), + ('configure', 'Configure'), + ('custom', 'Customize'), + ('final', 'Final'), + ] + + @api.model + def _default_project_id(self): + return self.env.context.get('active_id') + + def state_exit_start(self): + self.state = 'configure' + + def state_exit_configure(self): + self.state = 'custom' + + def state_exit_custom(self): + self.state = 'final' +``` + +Example of view (note the mode, must be primary): + +``` xml + + + + + my.wizard.form + my.wizard + primary + + + +

+ +

+ + + + + + + + + + + +
+

The project is now configured.

+
+
+
+
+ + + My Wizard + my.wizard + form + new + + form + +
+``` diff --git a/multi_step_wizard/static/description/icon.png b/multi_step_wizard/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/multi_step_wizard/static/description/icon.png differ diff --git a/multi_step_wizard/static/description/index.html b/multi_step_wizard/static/description/index.html new file mode 100644 index 0000000000..5fac99c896 --- /dev/null +++ b/multi_step_wizard/static/description/index.html @@ -0,0 +1,519 @@ + + + + + +Multi-Steps Wizards + + + +
+

Multi-Steps Wizards

+ + +

Beta License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runboat

+

This module is a base for creating multi-steps wizards. It does nothing +by itself.

+

Table of contents

+ +
+

Usage

+

Example of class:

+
+class MyWizard(models.TransientModel):
+    _name = 'my.wizard'
+    _inherit = ['multi.step.wizard.mixin']
+
+    project_id = fields.Many2one(
+        comodel_name='project.project',
+        name="Project",
+        required=True,
+        ondelete='cascade',
+        default=lambda self: self._default_project_id(),
+    )
+    name = fields.Char()
+    field1 = fields.Char()
+    field2 = fields.Char()
+    field3 = fields.Char()
+
+    @api.model
+    def _selection_state(self):
+        return [
+            ('start', 'Start'),
+            ('configure', 'Configure'),
+            ('custom', 'Customize'),
+            ('final', 'Final'),
+        ]
+
+    @api.model
+    def _default_project_id(self):
+        return self.env.context.get('active_id')
+
+    def state_exit_start(self):
+        self.state = 'configure'
+
+    def state_exit_configure(self):
+        self.state = 'custom'
+
+    def state_exit_custom(self):
+        self.state = 'final'
+
+

Example of view (note the mode, must be primary):

+
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+
+  <record id="my_wizard_form" model="ir.ui.view">
+    <field name="name">my.wizard.form</field>
+    <field name="model">my.wizard</field>
+    <field name="mode">primary</field>
+    <field name="inherit_id" ref="multi_step_wizard.multi_step_wizard_form"/>
+    <field name="arch" type="xml">
+      <xpath expr="//footer" position="before">
+        <h1>
+          <field name="name"
+                readonly="state != 'start'"
+                class="oe_inline"
+                placeholder="Name"/>
+        </h1>
+        <group name="configure" invisible="state != 'configure'">
+          <group>
+            <field name="field1"/>
+            <field name="field2"/>
+          </group>
+        </group>
+        <group name="custom" invisible="state != 'custom'">
+          <group>
+            <field name="field3"/>
+          </group>
+        </group>
+        <div name="final" invisible="state != 'final'">
+          <p>The project is now configured.</p>
+        </div>
+      </xpath>
+    </field>
+  </record>
+
+  <record id="open_my_wizard" model="ir.actions.act_window">
+      <field name="name">My Wizard</field>
+      <field name="res_model">my.wizard</field>
+      <field name="view_mode">form</field>
+      <field name="target">new</field>
+      <field name="binding_model_id" ref="project.model_project_project" />
+      <field name="binding_view_types">form</field>
+  </record>
+</odoo>
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/multi_step_wizard/tests/__init__.py b/multi_step_wizard/tests/__init__.py new file mode 100644 index 0000000000..d161186dd0 --- /dev/null +++ b/multi_step_wizard/tests/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import common +from . import test_multi_step_wizard diff --git a/multi_step_wizard/tests/common.py b/multi_step_wizard/tests/common.py new file mode 100644 index 0000000000..c872354e7d --- /dev/null +++ b/multi_step_wizard/tests/common.py @@ -0,0 +1,22 @@ +# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo_test_helper import FakeModelLoader + +from odoo.tests import common + + +class CommonTestMultiStepWizard(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .multi_step_wizard_test import MultiStepWizardTest + + cls.loader.update_registry((MultiStepWizardTest,)) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + return super().tearDownClass() diff --git a/multi_step_wizard/tests/multi_step_wizard_test.py b/multi_step_wizard/tests/multi_step_wizard_test.py new file mode 100644 index 0000000000..f5b772ce3f --- /dev/null +++ b/multi_step_wizard/tests/multi_step_wizard_test.py @@ -0,0 +1,13 @@ +# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class MultiStepWizardTest(models.TransientModel): + _name = "multi.step.wizard.test" + _description = "Multi Step Wizard Test" + _inherit = "multi.step.wizard.mixin" + + def state_previous_final(self): + self.write({"state": "start"}) diff --git a/multi_step_wizard/tests/test_multi_step_wizard.py b/multi_step_wizard/tests/test_multi_step_wizard.py new file mode 100644 index 0000000000..d50a825848 --- /dev/null +++ b/multi_step_wizard/tests/test_multi_step_wizard.py @@ -0,0 +1,23 @@ +# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import tagged + +from .common import CommonTestMultiStepWizard + + +@tagged("post_install", "-at_install") +class TestMultiStepWizard(CommonTestMultiStepWizard): + def setUp(self): + super().setUp() + self.MultiStepWizard = self.env["multi.step.wizard.test"] + + def test_behavior(self): + wizard = self.MultiStepWizard.create({}) + wizard.open_next() + self.assertEqual(wizard.state, "final") + with self.assertRaises(NotImplementedError): + wizard.open_next() + self.assertTrue(wizard.allow_back) + wizard.open_previous() + self.assertEqual(wizard.state, "start") diff --git a/multi_step_wizard/views/multi_step_wizard_views.xml b/multi_step_wizard/views/multi_step_wizard_views.xml new file mode 100644 index 0000000000..af9776954b --- /dev/null +++ b/multi_step_wizard/views/multi_step_wizard_views.xml @@ -0,0 +1,36 @@ + + + + multi.step.wizard.form + multi.step.wizard.mixin + +
+ + + + + +
+