Skip to Content
Menu
This question has been flagged
3 Replies
8950 Views

Hello,
If I have one field named=" test" in stock_picking

I want to readonly when state =  ( 'state', '=' , 'cancel') for incoming shipment
And for outgoing shipment other condition ( 'state' , 'in' , ('done' , 'cancel') )


Thanks in advance.


Avatar
Discard
Best Answer

Try this in view:

<field name='picking_type_code' invisible="1" />
<field name="test" attrs="{'readonly': ['|','&amp;',('picking_type_code','=','incoming'),('state', '=', 'cancel'),'&amp;',('picking_type_code','=','outgoing'),('state', 'in', ('done', 'cancel')) ]}"/>

Avatar
Discard
Author

Thank you.

Best Answer

No, You cannot, But you can use attributes
eg:-

<field name="test" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"/>

And you can have multiple conditions
You can refer: https://github.com/odoo/odoo/blob/12.0/addons/hr_holidays/views/hr_leave_allocation_views.xml

In your case, add this content to your view:

​<field name="test" attrs="{'readonly':  ['|','&amp;',('picking_type_code','=','incoming'),
('state', '=', 'cancel'),'&amp;',('picking_type_code','=','outgoing'),
('state', 'in', ('done', 'cancel')) ]}"/>
Avatar
Discard
Author

Thank you.

Best Answer

Hello,


You can try as following :


class StockPicking(models.Model):
_inherit= "stock.picking"

@api.multi
def _compute_readonly_test(self):

for record in self :
    read_test =False
    if record.picking_type_code == 'incoming' and record.state == 'cancel':
        read_test  = True
    elif record.picking_type_code == 'outgoing' and record.state in ('done','cancel') :
        read_test = True
    record.readonly_test = read_test


test = fields.Char(string="Test")
readonly_test = fields.Boolean(compute=_compute_readonly_test)


<field name="readonly_test" invisible="1"/>

<field name="test" attrs="{'readonly':[('readonly_test','=',True)]}"



Avatar
Discard
Author

Thank you.