Use tree mixin
issue7383 review45431002
This commit is contained in:
1 parent
dc2ce17abd
commit
ceff7fdc3b
1 file changed
+3
-25
@@ -6,7 +6,8 @@ from decimal import Decimal
|
||||
from functools import wraps
|
||||
|
||||
from trytond.model import (
|
||||
ModelSQL, ModelView, Workflow, DeactivableMixin, fields, sequence_ordered)
|
||||
ModelSQL, ModelView, Workflow, DeactivableMixin, fields, sequence_ordered,
|
||||
tree)
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
from trytond.transaction import Transaction
|
||||
@@ -15,8 +16,6 @@ from trytond.modules.product import price_digits
|
||||
|
||||
__all__ = ['WorkCenterCategory', 'WorkCenter', 'Work', 'WorkCycle']
|
||||
|
||||
SEPARATOR = ' / '
|
||||
|
||||
|
||||
class WorkCenterCategory(ModelSQL, ModelView):
|
||||
'Work Center Category'
|
||||
@@ -24,7 +23,7 @@ class WorkCenterCategory(ModelSQL, ModelView):
|
||||
name = fields.Char('Name', required=True, translate=True)
|
||||
|
||||
|
||||
class WorkCenter(DeactivableMixin, ModelSQL, ModelView):
|
||||
class WorkCenter(DeactivableMixin, tree(separator=' / '), ModelSQL, ModelView):
|
||||
'Work Center'
|
||||
__name__ = 'production.work.center'
|
||||
name = fields.Char('Name', required=True, translate=True)
|
||||
@@ -66,8 +65,6 @@ class WorkCenter(DeactivableMixin, ModelSQL, ModelView):
|
||||
def __setup__(cls):
|
||||
super(WorkCenter, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'wrong_name': ('Invalid work center name "%%s": '
|
||||
'You can not use "%s" in name field.' % SEPARATOR),
|
||||
'missing_work_center': ('Could not find a work center '
|
||||
'of category "%(category)s" under "%(parent)s".'),
|
||||
})
|
||||
@@ -84,25 +81,6 @@ class WorkCenter(DeactivableMixin, ModelSQL, ModelView):
|
||||
if len(locations) == 1:
|
||||
return locations[0].id
|
||||
|
||||
@classmethod
|
||||
def validate(cls, centers):
|
||||
super(WorkCenter, cls).validate(centers)
|
||||
for center in centers:
|
||||
center.check_name()
|
||||
|
||||
def check_name(self):
|
||||
if SEPARATOR in self.name:
|
||||
self.raise_user_error('wrong_name', (self.name,))
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.parent:
|
||||
return self.parent.get_rec_name(name) + SEPARATOR + self.name
|
||||
return self.name
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
return [('name',) + tuple(clause[1:])]
|
||||
|
||||
@classmethod
|
||||
def get_picker(cls):
|
||||
"""Return a method that picks a work center
|
||||
|
||||
Reference in new issue
Block a user