Skip to Content
Menu
This question has been flagged
7 Replies
8870 Views

HI Guys,

How can I use variables available to the form to be used in the lines on the same form.  I have the variable defined at the parent mode of "can_approve" and would like to use this in the attrs of a line level field to make readonly (code shown below):


                    <notebook>
<page string="Claim Details"> 
<field name="lines">
<tree create="true" delete="true" editable="true">
<field name='part_name' attrs="{'readonly':[('can_approve','=', True)]}" /> 
<field name='actual_amt' />
<field name='actual_price_unit' />
<field name='actual_qty'/>
                                                        </tree>

</field>

</page>

</notebook>


thoughts?


Thanks,
Damien

Avatar
Discard
Best Answer

Hi Damien,

I think you also need to declare your 'can_approve' field

'can_approve':field.Boolean(string="Can Approve", related='parent_id.can_approve')


Then,

<notebook>
<page string="Claim Details"> 
<field name="lines">
<tree create="true" delete="true" editable="true">

<field name="can_approve" invisible="1">
<field name="part_name" attrs="{'readonly':[('can_approve','=', True)]}" /> 
<field name="actual_amt" />
<field name="actual_price_unit" />
<field name="actual_qty"/>
</tree>

</field>

</page>

</notebook>



i hope this one would works.

Avatar
Discard
Best Answer

Hello,

use [('parent.can_approve','=',False)]. Not correct, regrefully

UPDATE

do the following:

  1. Add a related field on the python level. can_approve = fields.Boolean(related="comodel_field.can_approve",store=True). Where comodel_name - is a back reference from lines to parent. As alternative make it computed

  2. Add this field to columns. Use it without a parent in attrs.

Avatar
Discard
Author

Unfortunately no this doesn't work....

"Uncaught Error: QWeb2 - template['ListView.rows']: Runtime Error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Unknown field claim.claim.can_approve in domain [["parent.can_approve","=",true]]"

Any other thoughts?

Author

sorry, error is as follows:

Uncaught Error: QWeb2 - template['ListView.rows']: Runtime Error: Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Unknown field parent.can_approve in domain [["parent.can_approve","=",true]]"

Is can_approve placed on a parent form? Could you please send the xml view?

Author

<group>

<group>

<field name='can_approve' />

<field name='partner_id' options="{'no_create': True}" attrs="{'readonly':['|','&amp;','&amp;',('state','!=', 'new'),('state_approve','!=', 'pending_change'),('state','!=', 'part_code'),('can_approve','=', True)]}"/>

</group>

</group>

<notebook attrs="{'invisible': [('state', '=', 'new')]}">

<page string="Claim Details">

<field name="lines">

<tree create="true" delete="true" editable="true">

<field name='box_qty' invisible="context.get('claim_type') != 'goods_return'" attrs="{'readonly':[('parent.can_approve','=', True)]}" />

</tree>

</field>

</page>

</notebook>

Sorry for confusion: parent is available only domain and context.. not in attrs. I guess, the only way is to use a related field. Please look at the updated answer.