base/models/entity: return the current entity if no parent of the right level is found

refs #4015
This commit is contained in:
Benjamin Dauvergne 2014-01-20 09:33:19 +01:00
parent 9a4e653735
commit a0e0b69071
1 changed files with 6 additions and 3 deletions

View File

@ -109,10 +109,13 @@ class Entity(models.Model):
get_description.short_description = _(u'Description')
def level1_parent(self):
'''
Show parent of level between 1 or 3 if found, self return the current entity.
'''
parents = self.parents()
if len(parents) > 1:
return parents[1]
return None
if len(parents) > 3:
return parents[3]
return self
class AccountingCode(models.Model):
class Meta: