Files
tryton/category.py
T

41 lines
1.4 KiB
Python
Raw Normal View History

2008-06-23 20:55:06 +02: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.
2008-03-03 18:36:08 +01:00
from trytond.osv import fields, OSV
2008-03-04 11:56:55 +01:00
2008-03-03 18:36:08 +01:00
class Category(OSV):
"Product Category"
_name = "product.category"
_description = __doc__
name = fields.Char('Name', required=True, translate=True)
2008-05-13 11:47:29 +02:00
complete_name = fields.Function('get_complete_name', type="char",
string='Complete Name')
parent = fields.Many2One('product.category','Parent', select=1)
2008-03-03 18:36:08 +01:00
childs = fields.One2Many('product.category', 'parent',
2008-04-08 17:26:15 +02:00
string='Childs')
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'))
2008-04-22 17:49:25 +02:00
def get_complete_name(self, cursor, user, ids, name, arg, context=None):
res = self.name_get(cursor, user, ids, context=context)
2008-03-03 18:36:08 +01:00
return dict(res)
def name_get(self, cursor, user, ids, context=None):
2008-06-07 21:18:45 +02:00
if not ids:
2008-03-03 18:36:08 +01:00
return []
2008-06-07 21:18:45 +02:00
if isinstance(ids, (int, long)):
ids = [ids]
2008-03-03 18:36:08 +01:00
categories = self.browse(cursor, user, ids, context=context)
res = []
for category in categories:
if category.parent:
name = category.parent.name+' / '+ category.name
else:
name = category.name
res.append((category.id, name))
return res
Category()