parent
f7fc4c9c96
commit
bb36fe7364
31
menu.py
31
menu.py
|
@ -1,17 +1,16 @@
|
||||||
# This file is part product_esale module for Tryton.
|
# This file is part product_esale module for Tryton.
|
||||||
# The COPYRIGHT file at the top level of this repository contains
|
# The COPYRIGHT file at the top level of this repository contains
|
||||||
# the full copyright notices and license terms.
|
# the full copyright notices and license terms.
|
||||||
from trytond.model import ModelView, ModelSQL, fields
|
from trytond.model import ModelView, ModelSQL, fields, tree
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from .tools import slugify
|
from .tools import slugify
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['CatalogMenu']
|
__all__ = ['CatalogMenu']
|
||||||
|
|
||||||
|
|
||||||
class CatalogMenu(ModelSQL, ModelView):
|
class CatalogMenu(tree(separator=' / '), ModelSQL, ModelView):
|
||||||
"eSale Catalog Menu"
|
"eSale Catalog Menu"
|
||||||
__name__ = 'esale.catalog.menu'
|
__name__ = 'esale.catalog.menu'
|
||||||
|
|
||||||
|
@ -57,11 +56,6 @@ class CatalogMenu(ModelSQL, ModelView):
|
||||||
super(CatalogMenu, cls).__setup__()
|
super(CatalogMenu, cls).__setup__()
|
||||||
cls._order.insert(0, ('name', 'ASC'))
|
cls._order.insert(0, ('name', 'ASC'))
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def validate(cls, menus):
|
|
||||||
super(CatalogMenu, cls).validate(menus)
|
|
||||||
cls.check_recursion(menus, rec_name='name')
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def copy(cls, menus, default=None):
|
def copy(cls, menus, default=None):
|
||||||
raise UserError(gettext('product_esale.not_copy'))
|
raise UserError(gettext('product_esale.not_copy'))
|
||||||
|
@ -72,27 +66,6 @@ class CatalogMenu(ModelSQL, ModelView):
|
||||||
else:
|
else:
|
||||||
return self.slug
|
return self.slug
|
||||||
|
|
||||||
def get_rec_name(self, name):
|
|
||||||
if self.parent:
|
|
||||||
return self.parent.get_rec_name(name) + ' / ' + self.name
|
|
||||||
else:
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def search_rec_name(cls, name, clause):
|
|
||||||
if isinstance(clause[2], basestring):
|
|
||||||
values = clause[2].split('/')
|
|
||||||
values.reverse()
|
|
||||||
domain = []
|
|
||||||
field = 'name'
|
|
||||||
for name in values:
|
|
||||||
domain.append((field, clause[1], name.strip()))
|
|
||||||
field = 'parent.' + field
|
|
||||||
else:
|
|
||||||
domain = [('name',) + tuple(clause[1:])]
|
|
||||||
ids = [w.id for w in cls.search(domain, order=[])]
|
|
||||||
return [('parent', 'child_of', ids)]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_topmenu(cls, parent):
|
def get_topmenu(cls, parent):
|
||||||
"""Get Top Menu
|
"""Get Top Menu
|
||||||
|
|
Loading…
Reference in New Issue