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.
|
2018-03-19 17:17:02 +01:00
|
|
|
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
|
|
|
|
2010-01-13 00:37:34 +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'
|
2020-03-17 20:08:12 +01:00
|
|
|
name = fields.Char(
|
|
|
|
|
"Name", required=True, translate=True,
|
2017-03-16 18:32:07 +01:00
|
|
|
help="The main identifier of the category.")
|
2020-03-17 20:08:12 +01:00
|
|
|
parent = fields.Many2One(
|
2022-10-11 00:44:49 +02:00
|
|
|
'party.category', "Parent",
|
2017-03-16 18:32:07 +01:00
|
|
|
help="Add the category below the parent.")
|
2020-03-17 20:08:12 +01:00
|
|
|
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__()
|
2015-06-22 16:59:29 +02:00
|
|
|
t = cls.__table__()
|
2012-09-24 22:10:20 +02:00
|
|
|
cls._sql_constraints = [
|
2018-03-19 17:17:02 +01:00
|
|
|
('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'),
|
2013-03-07 16:55:03 +01:00
|
|
|
]
|
2015-01-02 15:48:40 +01:00
|
|
|
cls._order.insert(0, ('name', 'ASC'))
|