2009-02-17 11:46:14 +01:00
|
|
|
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
#this repository contains the full copyright notices and license terms.
|
2009-02-28 17:00:24 +01:00
|
|
|
from trytond.model import ModelView, ModelSQL, fields
|
2008-03-03 18:36:08 +01:00
|
|
|
|
2012-09-24 22:18:00 +02:00
|
|
|
__all__ = ['Category']
|
|
|
|
|
|
2008-03-04 11:56:55 +01:00
|
|
|
|
2009-02-28 17:00:24 +01:00
|
|
|
class Category(ModelSQL, ModelView):
|
2008-03-03 18:36:08 +01:00
|
|
|
"Product Category"
|
2012-09-24 22:18:00 +02:00
|
|
|
__name__ = "product.category"
|
2008-09-17 12:32:45 +02:00
|
|
|
name = fields.Char('Name', required=True, translate=True)
|
2012-04-03 20:07:18 +02:00
|
|
|
parent = fields.Many2One('product.category', 'Parent', select=True)
|
2008-03-03 18:36:08 +01:00
|
|
|
childs = fields.One2Many('product.category', 'parent',
|
2009-03-19 19:57:09 +01:00
|
|
|
string='Children')
|
2008-03-03 18:36:08 +01:00
|
|
|
|
2012-09-24 22:18:00 +02:00
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super(Category, cls).__setup__()
|
|
|
|
|
cls._order.insert(0, ('name', 'ASC'))
|
2011-04-23 12:01:33 +02:00
|
|
|
|
2012-09-24 22:18:00 +02:00
|
|
|
cls._constraints += [
|
2011-04-15 17:16:36 +02:00
|
|
|
('check_recursion', 'recursive_categories'),
|
2012-09-24 22:18:00 +02:00
|
|
|
]
|
|
|
|
|
cls._error_messages.update({
|
|
|
|
|
'recursive_categories': \
|
|
|
|
|
'You can not create recursive categories!',
|
|
|
|
|
})
|
2008-04-22 17:49:25 +02:00
|
|
|
|
2012-09-24 22:18:00 +02:00
|
|
|
def get_rec_name(self, name):
|
|
|
|
|
if self.parent:
|
|
|
|
|
return self.parent.get_rec_name(name) + ' / ' + self.name
|
|
|
|
|
else:
|
|
|
|
|
return self.name
|