2

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
  • hello, what is return when we call the write function – Nguyen Jan 18 '22 at 07:43
  • The return value of the write method should be boolean and is not evaluated like actions. So returning a dictionary like an action in your example won't work in write. – CZoellner Jan 18 '22 at 08:47
  • @Nguyen basically write function should return the changed record but in changing_status function I have to delete the record in this case ,so I want to close form view and come back to tree view and reload the tree view but I don't know how – reyhane janboori Jan 18 '22 at 11:33
  • @CZoellner I tried return True but cause record doesn't exist anymore it's not working also I want close form view and reload tree view automatically ... – reyhane janboori Jan 18 '22 at 11:36
  • Hi, i understand your requirements, but doing this in odoo isn't easy and i think not even possible in that simple way. Maybe using a assistant/wizard as intermediate could work. – CZoellner Jan 18 '22 at 14:17

1 Answers1

1

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'
        }