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.
Welcome!
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
This question has been flagged
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.