How to handle ConcurrencyException


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'

        #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

    def check_out(cls, lines):
        for line in lines:
            line.state = 'done'

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?