Hello all,
I'm adding a new field in form view only using fields_view_get but I'm getting this error(ValueError: Invalid field 'task_binary_field_new' on model 'project.task').
Here is my code:-
def fields_view_get (self, view_id = None, view_type = 'form', toolbar = False, submenu = False):
res = super (AdditionalField, self) .fields_view_get (
view_id = view_id, view_type = view_type, toolbar = toolbar, submenu = submenu)
if view_type == 'form':
doc = etree.fromstring (res ['arch'])
for node in doc.xpath ("// field [@ specialbinary = '1']"):
field_names = node.get ('name')
new_field_name = field_names + '_new'
field_string = res ['fields'] [field_names] ['string'] or ''
modifiers = node.get ('modifiers') [1: -1]
if modifiers:
modifiers + = ','
node.set ('modifiers', '{}')
node.set ('filename', new_field_name)
new_field = etree.Element ('field')
new_field.set ('name', new_field_name)
new_field.set ('invisible', '1')
new_field.set ('modifiers', '{' + modifiers + '}')
res ['fields'] [new_field_name] = {
'string': field_string, 'type': 'char'}
node.getparent (). append (new_field)
res ['arch'] = etree.tostring (doc)
return res
> specialbinary is an attribute of field that I've defined in xml.
Thanks!