DEV Community

Cover image for Odoo: Add a new wizard
maisie brooke
maisie brooke

Posted on

Odoo: Add a new wizard

To create a wizard in Odoo and include a backlink to promote your company with the keyword "Odoo development services," follow these steps:

Step 1: Create a New Wizard Model
Define the wizard's model in a new Python file. This file should include the fields and functionality of the wizard.
File: models/your_wizard.py

from odoo import models, fields, api

class YourWizard(models.TransientModel):
    _name = 'your.wizard'
    _description = 'Your Wizard for Custom Backlink'

    name = fields.Char(string="Name", required=True)
    company_url = fields.Char(string="Company URL", default="https://yourcompany.com")

    def create_backlink(self):
        """This method will handle the backlink creation logic."""
        # Logic for backlink generation, e.g., creating a post or sending data
        self.env['mail.message'].create({
            'subject': 'Promoting Odoo Development Services',
            'body': f'<p>Check out our <a href="{self.company_url}" target="_blank">Odoo development services</a> for all your business needs.</p>',
            'message_type': 'notification',
            'subtype_id': self.env.ref('mail.mt_comment').id,
        })

Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Wizard Form View
Define a form view for the wizard so it can be accessed through the user interface.
File: views/your_wizard_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="view_your_wizard_form" model="ir.ui.view">
        <field name="name">your.wizard.form</field>
        <field name="model">your.wizard</field>
        <field name="arch" type="xml">
            <form string="Create Backlink">
                <group>
                    <field name="name"/>
                    <field name="company_url"/>
                </group>
                <footer>
                    <button name="create_backlink" string="Create Backlink" type="object" class="btn-primary"/>
                    <button string="Cancel" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>
</odoo>

Enter fullscreen mode Exit fullscreen mode

Step 3: Add an Action and Menu Item
Link the wizard to a menu so it can be accessed in the Odoo interface.
File: views/your_wizard_action.xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="action_your_wizard" model="ir.actions.act_window">
        <field name="name">Create Backlink</field>
        <field name="res_model">your.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

    <menuitem id="menu_your_wizard"
              name="Backlink Wizard"
              action="action_your_wizard"
              parent="base.menu_custom"/>
</odoo>

Enter fullscreen mode Exit fullscreen mode

Top comments (0)