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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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.
Try this in view:
<field name='picking_type_code' invisible="1" />
<field name="test" attrs="{'readonly': ['|','&',('picking_type_code','=','incoming'),('state', '=', 'cancel'),'&',('picking_type_code','=','outgoing'),('state', 'in', ('done', 'cancel')) ]}"/>
Thank you.
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': ['|','&',('picking_type_code','=','incoming'),
('state', '=', 'cancel'),'&',('picking_type_code','=','outgoing'),
('state', 'in', ('done', 'cancel')) ]}"/>
Thank you.
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)]}"
Thank you.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up