Reputation: 41
As we know, there is a button "Add an item" in tree view of form view, click button "Add an item" to create a new line of the one2many.
As we know, there is a field "state" in many models.
So, I try to fix that match the following two requirements:
1) when state is not "done", I can see "Add an item" and edit other lines.
2) when state is "done", "Add an item" is disappear and edit other lines.
I have tried a lot but failed.
Such as:
1)
<tree create="0" edit="1">
It's not dynamic, so it does't match any requirements.
2)
<tree create="[('state','!=','done')]" edit="1">
Does not take effect and gives an error.
Error message: "Unknown CORS error" "An unknown CORS error occured. The error probably originates from a JavaScript file served from a different origin. (Opening your browser console might give you a hint on the error.) "
3)
<tree create="state!='done'" edit="1">
Error is the same with above.
4)
<tree attrs="{'create':[('state','!=','done')]}" edit="1">
No effect or error.
Upvotes: 4
Views: 389
Reputation: 41
<field>
<tree attrs="{'create':[('parent.state','!=','done')]}">
</tree>
</field>
I made low-level mistakes!
That I replace the attrs in another module, and the "state" should be "parent.state".
Upvotes: 0
Reputation: 2825
Your idea is almost right, but you are putting those attributes in wrong tag. You are trying to make a field readonly, which field is in that case in tree
form inside a form
view. So all you have to do is set readonly condition in the field
tag, the One2many
for which the tree representation is added. So the code will be like:
<field name="one2many_field_name" attrs="{'readonly': [('state', '=', 'done')]}">
<tree editable="bottom">
.....
.....
</tree>
</field>
Also to be noted, you can set readonly condition to the field
definition itself in the Model
definition, in that case you don't have to define readonly condition in every view you are using that field in.
Upvotes: 2