Skip to Content
Menu
This question has been flagged
2697 Views

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!



Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1487
1
Nov 24
1196
2
Sep 24
1047
1
Aug 24
2456
3
Aug 24
2687