Domain for tree view inside in form view

Hi everyone. I have a form view with a one2many field, which I want to display as a tree (it has parent and childrens). The problem is that it shows me the children fields, inside and outside the parent, if I place the following filter in the field:

filter = [('parent', '=', None)]

It looks correctly, but when I want to load a parent it doesn’t allow me.

Thanks in advance.

If they are linked to the One2Many field, it is normal.
Trees inside One2Many are odds.

It is a way but I’m not sure that when you add a children to the tree it will be linked to the One2Many.

What do you mean by “load a parent”? and “not allow me”?

Thank you for the quick response. The code is as follows:

class ConstructionWork(ModelSQL, ModelView):
    'ConstructionWork'
    __name__ = 'construction_work.work'
    #other fields here
    lines = fields.One2Many('construction_work.line', 'construction_work', 'Lines', states={
        'readonly': Eval('work_state') != 'draft',
            },
        filter=[('parent', '=', None)],
        depends=['work_state'])
class ConstructionWorkLine(sequence_ordered(), ModelSQL, ModelView):
    'construction work line'
    __name__ = 'construction_work.line'
    construction_work = fields.Many2One('construction_work.work', 'ConstructionWork', ondelete='CASCADE',
        select=True, required=True)
    type = fields.Selection([
        ('line', 'Line'),
        ('section', 'Section'),
        ], 'Type', select=True, required=True)
    #other fields here
    parent = fields.Many2One(
        'construction_work.line', "Parent", select=True)
    childs = fields.One2Many(
        'construction_work.line', 'parent', string="Children")

The idea is to create sections where inside these I have the lines.

I mean I can’t select any line as a parent to a new line.

Will it not be simpler to use flat list but ordered with sequence (like the sale with title and subtotal)?

Of course because you put a filter that says the parent must be always None.
You will only be able to create children from the children One2Many in the form view of the line.

Thanks for the repply.

That is a simple solution, but the idea is to have sections.

How can I make it appear to add the existing records, in the One2Many form of the child, as in the invoice lines.

Sections can just be convention like in sale.

I guess you want to move an existing top level line under another one. For that you need to activate the drag and drop feature. This activated by setting a sequence attribute on the tree view.

Thank you very much! Dragging and dropping one line on top of the other allows me to create children.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.