Files
tryton/category.py
T

42 lines
1.3 KiB
Python
Raw Normal View History

#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
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"
_name = "product.category"
_description = __doc__
name = fields.Char('Name', required=True, translate=True)
2008-05-13 11:47:29 +02:00
parent = fields.Many2One('product.category','Parent', select=1)
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
2008-04-22 17:49:25 +02:00
def __init__(self):
super(Category, self).__init__()
self._order.insert(0, ('name', 'ASC'))
2011-04-23 12:01:33 +02:00
self._constraints += [
('check_recursion', 'recursive_categories'),
]
self._error_messages.update({
'recursive_categories': 'You can not create recursive categories!',
})
2008-04-22 17:49:25 +02:00
2010-08-15 00:23:46 +01:00
def get_rec_name(self, ids, name):
2008-06-07 21:18:45 +02:00
if not ids:
return {}
res = {}
def _name(category):
if category.id in res:
return res[category.id]
elif category.parent:
return _name(category.parent) + ' / ' + category.name
2008-03-03 18:36:08 +01:00
else:
return category.name
2010-08-15 00:23:46 +01:00
for category in self.browse(ids):
res[category.id] = _name(category)
2008-03-03 18:36:08 +01:00
return res
Category()