Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
14 Views

Hey Cyllo community! Anyone have any tips or gotchas to watch out for when working with TransientModel wizards? I'm running into some [brief, specific problem - e.g., weird update behavior] and could use a hand.

Avatar
Discard

Here's how you can implement a simple wizard in Odoo. This example allows you to change the status of multiple records at once.

Python Code – example_batch_update_wizard.py
from odoo import api, fields, models
class ExampleBatchUpdateWizard(models.TransientModel):
​_name = 'example.batch.update.wizard'
  ​_description = 'Example Batch Update Wizard'

  ​new_status = fields.Selection([ ('new', 'New'), ('processed', 'Processed'), ​ ('archived', 'Archived'), ], string="Set Status To", required=True) ​ def action_apply_update(self):
  ​""" Batch update 'status' field on selected example.model records. The ​active_ids come from context (selected records). """
​active_ids = self.env.context.get('active_ids', [])
  ​if active_ids:
  ​records = self.env['example.model'].browse(active_ids)​  ​records.write({'status': self.new_status})
​records.write({'status': self.new_status})
  ​return {'type': 'ir.actions.act_window_close'}


XML Code – example_batch_update_wizard_view.xml 

   

        example.batch.update.wizard.view.form

        example.batch.update.wizard

       

           

               

                   

               

               

                   

                   

               

           

       

   


   

        Batch Update Status

        example.batch.update.wizard

        form

        new

   


Remember to replace 'example.model' with the actual name of your model. This code provides a basic functional wizard; you can extend it with more fields and logic as needed.

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!