Adapt check_recursion to 5.0

This commit is contained in:
Javier Uribe 2019-02-26 18:07:11 +01:00
parent 6c4e519c63
commit 19bb8fa8e0
2 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,7 @@
from trytond.model import ModelSQL, ModelView, fields, Unique, DeactivableMixin
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import (ModelSQL, ModelView, fields, Unique,
DeactivableMixin, tree)
from trytond.pyson import Eval
__all__ = ['Category']
@ -11,7 +14,7 @@ DEPENDS = ['active']
SEPARATOR = ' / '
class Category(DeactivableMixin, ModelSQL, ModelView):
class Category(tree(), DeactivableMixin, ModelSQL, ModelView):
'''Category'''
__name__ = 'timesheet.work.category'
name = fields.Char('Name', required=True)
@ -36,7 +39,6 @@ class Category(DeactivableMixin, ModelSQL, ModelView):
@classmethod
def validate(cls, categories):
super(Category, cls).validate(categories)
cls.check_recursion(categories, rec_name='name')
for category in categories:
category.check_name()

View File

@ -26,7 +26,7 @@ class TimesheetWorkCategoryTestCase(ModuleTestCase):
category1, = Category.create([{
'name': 'Category 1',
}])
self.assert_(category1.id)
self.assertTrue(category1.id)
@with_transaction()
def test_category_recursion(self):
@ -40,7 +40,7 @@ class TimesheetWorkCategoryTestCase(ModuleTestCase):
'name': 'Category 2',
'parent': category1.id,
}])
self.assert_(category2.id)
self.assertTrue(category2.id)
self.assertRaises(Exception, Category.write, [category1], {
'parent': category2.id,