Files
tryton/modules/product_classification/product.py
T

83 lines
2.5 KiB
Python
Raw Normal View History

2016-03-16 09:46:14 +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.
2021-12-11 17:58:43 +01:00
from trytond.model import (
DeactivableMixin, ModelStorage, ModelView, fields, tree)
from trytond.pool import Pool, PoolMeta
2016-03-16 09:46:14 +01:00
2018-03-26 14:11:05 +02:00
class ClassificationMixin(DeactivableMixin):
2019-09-07 23:45:08 +02:00
__slots__ = ()
2016-03-16 09:46:14 +01:00
name = fields.Char('Name', translate=True, required=True)
selectable = fields.Boolean("Selectable")
2016-03-16 09:46:14 +01:00
@classmethod
def default_selectable(cls):
return True
def classification_tree(name):
'Return a ClassificationMixin with tree structure'
2018-05-12 00:49:51 +02:00
class ClassificationTreeMixin(tree(separator=' / '), ClassificationMixin):
2019-09-07 23:45:08 +02:00
__slots__ = ()
parent = fields.Many2One(name, "Parent")
2016-03-16 09:46:14 +01:00
childs = fields.One2Many(name, 'parent', 'Children')
return ClassificationTreeMixin
2018-06-26 19:11:49 +02:00
class Template(metaclass=PoolMeta):
2016-03-16 09:46:14 +01:00
__name__ = 'product.template'
classification = fields.Reference(
"Classification", selection='get_classification')
@classmethod
def __setup__(cls):
super().__setup__()
for model in cls._get_classification():
if model in cls.classification.domain:
cls.classification.domain[model] = [
cls.classification.domain[model],
('selectable', '=', True),
]
else:
cls.classification.domain[model] = [
('selectable', '=', True),
]
2016-03-16 09:46:14 +01:00
@classmethod
def _get_classification(cls):
'Return list of Model names for classification Reference'
return []
@classmethod
def get_classification(cls):
pool = Pool()
Model = pool.get('ir.model')
2020-12-27 00:19:30 +01:00
get_name = Model.get_name
2016-03-16 09:46:14 +01:00
models = cls._get_classification()
2020-12-27 00:19:30 +01:00
return [(None, '')] + [(m, get_name(m)) for m in models]
2016-03-16 09:46:14 +01:00
2018-06-26 19:11:49 +02:00
class Product(metaclass=PoolMeta):
2016-03-16 09:46:14 +01:00
__name__ = 'product.product'
@classmethod
def get_classification(cls):
pool = Pool()
Template = pool.get('product.template')
return Template.get_classification()
class ClassificationDummy(ClassificationMixin, ModelStorage, ModelView):
'Dummy Product Classification'
__name__ = 'product.classification.dummy'
class ClassificationTreeDummy(
classification_tree('product.classification_tree.dummy'),
ModelStorage, ModelView):
'Dummy Product Classification Tree'
__name__ = 'product.classification_tree.dummy'