Search code examples
pythonxmlodooodoo-13

come back to tree view when user click on save button in odoo 13.0


I override the write function in my model for calling my function that is manually set changing in DB, actually I delete this record from table in this function after that I want comeback to tree view automatically and I don't have the changed record anymore to return because of that I stuck in write function and it doesn't finished by the way without calling my function I still can't comeback to tree view with return action(I tried any form of return action it didn't work at all) :

def write(self, vals):
     self.changing_status(vals)
     action = {
    'name': _('Cash Control'),
    'view_mode': 'tree',
    'view_type': 'form',
    'res_model': 'wfwodoovitemsstatuscurrent',
    'view_id': self.env.ref('nmdi_workflow.list').id,
    'type': 'ir.actions.act_window',
    'target': 'current'
}
return action

Solution

  • I solved this by adding a button on the tree view and adding a wizard instead of form view.so, I considered a transient model for this wizard and then added the default values using a function then I added a button with the save name, then I manually made the changes to the table and set an action to return for come back to tree view and update that again.

    class WfwU1001W1(models.TransientModel):
        _name = 'wfwu1001wizard1'
    
        field1 = fields.Integer( default=lambda self: self._get_data('field1'))
        field2 = fields.Integer( default=lambda self: self._get_data('field2'))
    
     @api.model
        def _get_data(self, field_name):
            id = self.env.context.get("active_id")
            if id:
                return self.env['wfwodoovitemsstatuscurrent'].browse(id).mapped(field_name)[0]
    
    
     def save_changing_action(self):
    # do some logic and save manually
    
            return {
                'name': 'closewizard',
                'view_type': 'tree',
                'view_mode': 'tree',
                'res_model': 'wfwodoovitemsstatuscurrent',
                'view_id': False,
                'views': [(self.env.ref('nmdi_workflow.list').id, 'tree')],
                'type': 'ir.actions.act_window'
            }