# -*- coding: utf-8 -*- # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields, tree from trytond.modules.cashbook.model import order_name_hierarchical from trytond.transaction import Transaction class Category(tree(separator=' / '), ModelSQL, ModelView): "Cashbook Category" __name__ = "cashbook.bookcategory" company = fields.Many2One(string='Company', model_name='company.company', required=True, ondelete="RESTRICT") name = fields.Char(string='Name', required=True, translate=True) parent = fields.Many2One(string='Parent', select=True, model_name='cashbook.bookcategory', ondelete='CASCADE', left='left', right='right') childs = fields.One2Many(string='Children', field='parent', model_name='cashbook.bookcategory') left = fields.Integer(string='Left', required=True, select=True) right = fields.Integer(string='Right', required=True, select=True) @classmethod def __setup__(cls): super(Category, cls).__setup__() cls._order.insert(0, ('rec_name', 'ASC')) @staticmethod def default_left(): return 0 @staticmethod def default_right(): return 0 @staticmethod def default_company(): return Transaction().context.get('company') or None @staticmethod def order_rec_name(tables): """ order by pos a recursive sorting """ return order_name_hierarchical('cashbook.bookcategory', tables) # ende Category