Skip to Content
Menu
This question has been flagged
1890 Views

Hiii

I want create a field in department form to set level of each department

So I defined a field with name : “level” in this way:

    level = fields.Integer('Level', compute="_calc_level" ,store=True)

and defined this function:

 

    def _calc_level(self):

        for obj in self.browse(self.ids):

            if obj.parent_id:

                obj.level = obj.parent_id.level+1

            else:

                obj.level = 1

my data are:

Name of department

Id of department

Parent_id

level

A

1

-

1

B

2

1

2

C

3

2

3

D

4

2

3

E

5

4

1

F

6

4

1

G

7

4

1

  So departments “E,F,G” doesn’t have current level

But I don’t know what is wrong in my function?? 

Thanks

Avatar
Discard

Try to debug or make some tests for seeing what is going on.