How to handle ConcurrencyException

Hi,

I have this follow issue. In a field one2many in a tree view I have a button that modify the state of the line, but after the button is pressed the follow message is displayed

trytond.exceptions.ConcurrencyException: Records were modified in the meanwhile

And tried this code to avoid the notification but doesn’t work

        line.state = 'done'
        line.save()

        #cls.write([line], {'state': 'done'})

Thanks in advance!

Normally after clicking on a button the client reload the related record so there should be no concurrency.
Are you sure to modify the right record? Is the record correctly reloaded?

Full code is

    @classmethod
    @ModelView.button
    def check_out(cls, lines):
        for line in lines:
            line.validate_complete()
            line.state = 'done'
            line.save()

I’m not sure how to reload record correctly. Need to update parent record, if yes, how?

You have nothing to do, the client must do it. Could you check that?

For example, the client open the record, check the pending lines and if someone is confirmed it click on it to mark as finished.

The code of button is showed above, is all code I need to do it?