How can I reset a form in Odoo with one instruction?

1.2k Views Asked by At

I would like to reset all the fields of one form with one instruction in Odoo v8. Is that possible? If not, I will have to reset each field one by one and that is not very clean code

1

There are 1 best solutions below

1
On BEST ANSWER

You can assign to all fields (except MAGIC_COLUMNS) the values of the empty model.



from openerp import models

# ... other code

    @api.multi
    def reset(self):
        empty_obj = self.env[self._name]

        for key, value in self._fields.iteritems():
            if value.name not in models.MAGIC_COLUMNS:
                setattr(self, key, getattr(empty_obj, key))