Files
tryton/modules/party/category.py
T

41 lines
1.4 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 (
2018-05-12 00:48:48 +02:00
ModelView, ModelSQL, DeactivableMixin, fields, Exclude, 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", select=True,
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'))
2008-02-15 17:42:25 +01:00
@classmethod
def __register__(cls, module_name):
super(Category, cls).__register__(module_name)
2018-07-24 22:01:08 +02:00
table_h = cls.__table_handler__(module_name)
# Migration from 4.6: replace unique by exclude
table_h.drop_constraint('name_parent_uniq')