Enable Dark Mode!
how-to-perform-advanced-wizard-operations-from-active-model-in-odoo-18.jpg
By: Sruthi M

How to Perform Advanced Wizard Operations From Active Model in Odoo 18

Technical

In Odoo, wizards are transient models used for temporary user interactions like pop-ups or multi-step actions. In Odoo 18, advanced wizard operations can be achieved by leveraging the TransientModel class, which allows for temporary data storage and interaction with active models. When doing advanced operations from a wizard based on the active model, we typically use the context to interact with the records the wizard is acting upon.

Here’s a detailed explanation of how to perform advanced wizard operations from the active model in Odoo 18:

In invoices, we have a wizard for creating payment links and amounts from the invoice. Ie,

How to Perform Advanced Wizard Operations From Active Model in Odoo 18-cybrosys

After clicking the action, it will open a new wizard to generate a payment link.

How to Perform Advanced Wizard Operations From Active Model in Odoo 18-cybrosys

We can store the payment link and amount to certain fields of the model account.move. For that, we can use the following code.

Python Code :

class LinkInvoice(models.Model):
   _inherit = 'account.move'
   payment_link = fields.Char("Payment Link", compute='compute_payment_link')
   amount = fields.Char(string="Amount")
   def compute_payment_link(self):
       self.payment_link = False
       for rec in self:
           account_move_form =          
           Form(self.env['payment.link.wizard'].with_context
           (active_id=rec.id,      active_model='account.move'))
           self.payment_link = account_move_form.link
           self.amount = account_move_form.amount

XML Code:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
      <!-- Extend the existing form view for account.move -->
      <record id="view_account_move_form" model="ir.ui.view">
          <field name="name">account.move.form.inherit</field>
          <field name="model">account.move</field>
          <field name="inherit_id" ref="account.view_move_form"/>
          <field name="arch" type="xml">
              <!-- Add the 'payment_link' field to the existing form view -->
              <field name="invoice_date" position="after">
                  <field name="payment_link" widget="CopyClipboardChar"/>
                  <field name="amount"/>
              </field>
          </field>
      </record>
</odoo>

In this example, the compute_payment_link method computes the payment link and amount by creating a form for the payment.link.wizard model and accessing its fields. The with_context method is used to pass the active model and record ID to the wizard.

The Form class comes from odoo.tests.common and is usually used in tests to simulate UI interactions. But you can also creatively use it in certain backend scenarios — like inside a wizard — to simulate fetching field values as if they were in a form view (especially useful for computed fields or fields that require form context).

How to Perform Advanced Wizard Operations From Active Model in Odoo 18-cybrosys

Here we can see the values of corresponding fields inside invoice form.

So in Odoo 18, advanced wizard operations typically involve creating custom wizard models, handling complex user inputs, and performing actions based on that input. Wizards are often used for tasks that require user interaction, such as creating invoices, performing mass actions on records, or updating configurations.

To read more about Advanced Wizard Operations from Active Model in Odoo 17, refer to our blog Advanced Wizard Operations from Active Model in Odoo 17.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message