Files
tryton/modules/party/category.py
T

33 lines
1.1 KiB
Python
Raw Normal View History

2014-12-02 12:55:24 +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.
from sql.conditionals import Coalesce
from sql.operators import Equal
2018-03-26 14:10:40 +02:00
from trytond.model import (
2021-12-11 17:58:42 +01:00
DeactivableMixin, Exclude, ModelSQL, ModelView, fields, tree)
2008-02-26 12:41:13 +01:00
2018-05-12 00:48:48 +02:00
class Category(DeactivableMixin, tree(separator=' / '), ModelSQL, ModelView):
2008-05-21 18:12:20 +02:00
"Category"
2012-09-24 22:10:20 +02:00
__name__ = 'party.category'
name = fields.Char(
"Name", required=True, translate=True,
2017-03-16 18:32:07 +01:00
help="The main identifier of the category.")
parent = fields.Many2One(
'party.category', "Parent",
2017-03-16 18:32:07 +01:00
help="Add the category below the parent.")
childs = fields.One2Many(
'party.category', 'parent', "Children",
2017-03-16 18:32:07 +01:00
help="Add children below the category.")
2008-03-04 11:50:22 +01:00
2012-09-24 22:10:20 +02:00
@classmethod
def __setup__(cls):
super(Category, cls).__setup__()
t = cls.__table__()
2012-09-24 22:10:20 +02:00
cls._sql_constraints = [
('name_parent_exclude',
Exclude(t, (t.name, Equal), (Coalesce(t.parent, -1), Equal)),
2018-12-29 14:20:29 +01:00
'party.msg_category_name_unique'),
]
2015-01-02 15:48:40 +01:00
cls._order.insert(0, ('name', 'ASC'))