Enable Dark Mode!
advanced-wizard-operations-from-active-model-in-odoo-16.jpg
By: Mily Shajan

Advanced Wizard Operations from Active Model in Odoo 16

Technical Odoo 16

Wizards in Odoo helps to enhance the user experience. Wizards are created by the Transient Model class, which cannot store data permanently and delete the data periodically. Wizards perform the operations on permanent models.

Wizards are opened as ir_act_window, which redirects to a new popup window. Inside that popup view, it shows the fields and button actions. Normally users have permission to record in the wizards.

Here, this blog illustrates some advanced wizard operations, for example, how we can get that button action inside a wizard to our active model. Normally button action for the wizard is called within the transient model of the wizard.

Here is the wizard for generating payment links from invoices ie,account.move

advanced-wizard-operations-from-active-model-in-odoo-16-1-cybrosys

If we need to show the payment link in this wizard to a particular field which can be done using this Form.

from odoo.tests import Form
class LinkInvoice(models.Model):
   _inherit = 'account.move'  
   payment_link = fields.Char("Payment Link",compute='compute_payment_link')
   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'))
           link = account_move_form.link

Here, we created a new field link inside the account.move model which is called by a compute function. Inside the compute, the payment_link from payment.link.wizard is updated to the field in account.move. This can be done using Form, where the form is imported from Odoo.tests and calls the Form along with the transient model of wizard with_context of active_id as the id of the record of active_model,active_model is the model that we need to show the data.

Form - By calling Form, we can get relevant changes on "creation”, relevant onchanges on setting fields, properly handle defaults & onchanges around x2many fields

Active_id - id of record that needs to show the value

Active_model - model where need to show the value

After executing this code it shows

advanced-wizard-operations-from-active-model-in-odoo-16-2-cybrosys

Payment_link is shown on the field that is inside the active_model form. Likewise, we can call other fields in wizard button actions inside the wizard to the active_model in Odoo 16.

Usually, Transient models store data temporarily and delete periodically, using these advanced operations with the help of Form we can store the field values in the transient model to our active model and corresponding record.


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



0
Comments



Leave a comment

 


whatsapp
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