How to use parent class field on Eval for One2Many field

Dear Tryton team,
I want to keep all my fields on read-only once the state of my inspection is done, using the states and Eval seems to work, unfortunately for the One2Many fields I can’t figure it out how to eval a field from my source class, here’s the example:

class Inspection(ModelSQL, ModelView):
    'Inspection'
    __name__ = 'my.module.inspection'

    STATES = {'readonly': Eval('state') == 'done'} # this work for inspection fields
    
    # details are readonly but I still can change description field
    details = fields.One2Many(
        'my.module.details',
        'inspection', 'Inspection details',
        states = STATES)

class Details(ModelSQL, ModelView):
    'Details'
    __name__ = 'my.module.details'

    inspection = fields.Many2One(
        'my.module.inspection', 'inspection', readonly=True)
    STATES= ???
    # I tried below states but does not seem to work

    #STATES = {'readonly': Eval('inspection.state') == 'done'}
    #STATES = {'readonly': Eval('_parent_inspection.state') == 'done'} # I know this is close

    description = fields.Char('Descripcion', states=STATES)

Any clue will be appreciated. btw the Inspection class is part of a module, which inheritance from the parent module that has the state field

You should create a functional field on your details model that returns the state of the inspection (it can be computed with an on_change_with). Then you should evaluate this field on the readonly finition of all of the field of your details module and add it to depends.

If you look at the sale module, you can see an example on the Line class, which makes all the fields readonly when the sale state is diferent than draft

1 Like

Thanks as always Sergi , it worked following the sale module example. I hope you have a great weekend.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.