edbo
1
I want to make a button readonly based on a parent field. Normally you would do:
states = {
'readonly': Eval('_parent_sale', {}).get('state') != 'draft'
}
Now I want to do the same with a button, but that isn’t working.
@classmethod
def __setup__(cls):
super().__setup__()
cls._buttons.update({
confirm: {
'readonly': Eval('_parent_sale', {}).get('state') != 'draft'
}
})
Am I doing something wrong or is this a limitation? Or is it possible to add this to the XML?
pokoli
(Sergi Almacellas Abellana)
2
In such case the best is to have a function field (which depends on the parent) to compute the state and then make your button depend on such field.
Indeed, following your example we no more use _parent_sale.state
but we have a sale_state
field on the line.
This has the benefit that the button have the right state also when used outside of the _parent
model. For example on a view that just show lines.
1 Like
edbo
3
Yeah, I already was afraid of that. So I added a Function
field.
ced
(Cédric Krier)
4
It should work if you are inside a One2Many
for which the parent is sale
.
edbo
5
I’m working with a Many2One
as parent
. So I want to look at the state
field of the parent
.
ced
(Cédric Krier)
6
A Many2One
does not create a parent/children relation, only the One2Many
.
So the Function
field is the solution.
edbo
7
Thanks! That’s something to remember.
system
(system)
Closed
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.