Odoo / Model / Transient model - wizard - dialog box
Transient Model - Wizard - DialogBox
-
Step 1:
Transient models:
It's based on the model TransientModel class. Moreover, the data stored in the database is temporary in this class which is periodically cleared data from the database table.
- Records in the wizard require only temporary storage, so they are deleted after some time from the database.
- Users have all permissions on wizard records, they don't require explicit access rights.
- Records in the wizard can refer through many2one fields or to regular records, but regular records cannot refer through many2one fields or to wizard records.
model
class MrpProductWizard(models.TransientModel): _name = 'mrp.product.produce.wizard' produce_line_ids = fields.One2many('mrp.product.produce.wizard.line', 'product_produce_id', string='Product to Track') # Method to mark the mrp orders as done def action_done(self): for line in self.produce_line_ids.mapped('production_id'): line.button_mark_done() class MrpProductProduceWizardLine(models.TransientModel): _name = "mrp.product.produce.wizard.line" _description = "Record Production Line" product_produce_id = fields.Many2one('mrp.product.produce.wizard') production_id = fields.Many2one('mrp.production') product_id = fields.Many2one('product.product', 'Product') qty = fields.Float('Quantity') View
mrp.product.produce.wizard.view mrp.product.produce.wizard form wizard action
class MrpProduction(models.Model): _inherit = 'mrp.production' # Method for the wizard Mark as Done def action_done_show_wizard(self): production_ids = self.env['mrp.production'].browse(self._context.get('active_ids', False)) lines = [] for line in production_ids: vals = (0, 0, { 'production_id': line.id, 'product_id': line.product_id.id, 'qty': line.product_qty }) lines.append(vals) return {'type': 'ir.actions.act_window', 'name': _('Mark as Done'), 'res_model': 'mrp.product.produce.wizard', 'target': 'new', 'view_id': self.env.ref('multiple_mrp_orders.view_mrp_product_done_wizard').id, 'view_mode': 'form', 'context': {'default_produce_line_ids': lines} } Mark as Done ir.actions.server code action = model.action_done_show_wizard() Button