2

Normally when editing a model in Odoo, one can click the Discard button to revert all changes.

Now I have a button that performs some modifications on the model, for example it clears a field. Sadly this change is not reverted when clicking Discard. So I assume that the change I make to the model in code is directly persisted. How do I modify a model in a way, that the change is not directly persisted before clicking Save?

In other frameworks one often modifies a working-copy of a model, which can simply be discarded or applied to the real model. How does the Discard mechanism in Odoo work?

Example

In my view I have a button:

<header>
    <button string="Clear Filter" type="object" name="clear_filter"/>
</header>

And in my model I clear the filter like so:

def clear_filter(self):
    for record in self:
        record.filter = None

This works, but the modification of the field is directly persisted and cannot be discarded.

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
mihca
  • 997
  • 1
  • 10
  • 29
  • What is your use case? You can use `onchange` but there might be a better way depending on your use case. – George Daramouskas Jul 20 '18 at 19:19
  • 2
    A button call in Odoo will either call a create or write. Both calls will save everything into db. – CZoellner Jul 21 '18 at 09:53
  • Well I guess I have to live with this. My use case is that I modify some records on button click (e.g. add records to many2many, clear the filter as shown above). But these actions cannot be undone which breaks with the normal user expectations – mihca Jul 23 '18 at 17:17

0 Answers0