Hello,
I want to make many2one field readonly=false which is located in one2many field and this field follow the attribute readonly=true from the py file.
Here are defined invoice_line field in base module.
invoice_line = fields.One2many('account.invoice.line', 'invoice_id', string='Invoice Lines', readonly=True, states={'draft': [('readonly', False)]}, copy=True)
What i wan't is in this invoice_line field there is one m2o field is name which is description simply i want to make that field readonly=false whichever state follow the invoice. Below i just try the fields_view_get but didn't get any successful result.
@api.model
def fields_view_get(self, view_id=None, view_type='tree', toolbar=False, submenu=False):
# context = if self.env.context is None:context = {}
res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=False)
active_id = self.env['account.invoice'].browse(self.env.context.get('active_id'))
print "-----------------",active_id.state
if view_type == 'form':
fields = res.get('fields', {})
method_nodes = etree.XML(res['fields']['invoice_line']['views']['tree']['arch'])
for node in method_nodes.xpath("//field"):
modifiers = json.loads(node.get("modifiers", '{}'))
modifiers.update({'readonly':True})
node.set("modifiers", json.dumps(modifiers))
for node in method_nodes.xpath("//field[@name='name']"):
modifiers = json.loads(node.get("modifiers", '{}'))
modifiers.update({'readonly': False})
node.set("modifiers", json.dumps(modifiers))
res['fields']['invoice_line']['views']['tree']['arch'] = etree.tostring(method_nodes)
return res
Please give some suggestion.
Thanks in advance.