Commit 72fbe5ed authored by Jean-Paul Smets's avatar Jean-Paul Smets

Naming comments added. More important, we have here a generic composition...

Naming comments added. More important, we have here a generic composition system. At the same time, we are using asComposedDocument to bring at the level of a movement all the information which is necessary to generate movements in certain kinds of rules (trade model, transformation, etc.). We could call this a generic movement rewriting model and asComposedDocument builds it, with BPM interfaces and movement generator interfaces. However, "composed document" could be related to other things. One approach could be to consider that composed document follows a given relation (ex. specialise) to virtually populate a document (ex. a movement) with subobjects and add to the document any "methods" which are acquired through specialise. This would be a very generic concept of composition: it not only composes document subcontents (objectValues) but also composes classes through inheritance. Other applications could be considered in many fields. I think this is a really nice pattern.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@35002 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 97239903
......@@ -33,6 +33,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import transactional_cached
from Products.ERP5Type.Utils import sortValueList
from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5.Document.BusinessProcess import BusinessProcess
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
......@@ -75,6 +76,11 @@ def _getEffectiveModel(self, start_date=None, stop_date=None):
return model_list[0].getObject()
# XXX-JPS it is very likely that what must be cached is delivery based
# since most lines do not "specialise" a delivery - clever caching
# approach is possible, by keeping one cache at the delivery level
# and just accessing it from wherever needed. This could minimize number of
# caches in RAM and at the same time make things fast
@transactional_cached()
def _findPredicateList(container_list, portal_type=None):
predicate_list = []
......@@ -93,7 +99,7 @@ def _findPredicateList(container_list, portal_type=None):
return predicate_list
class asComposedDocument(object):
class asComposedDocument(object): # XXX-JPS bad name for a class - please follow conventions or explain
"""Return a temporary object which is the composition of all effective models
The returned value is a temporary copy of the given object. The list of all
......@@ -103,9 +109,11 @@ class asComposedDocument(object):
"""
def __new__(cls, orig_self, portal_type_list=None):
self = orig_self.asContext(_portal_type_list=portal_type_list)
self = orig_self.asContext(_portal_type_list=portal_type_list) # XXX-JPS orig_self -> original_self - please follow conventions
base_class = self.__class__
self.__class__ = type(base_class.__name__, (cls, base_class), {})
self.__class__ = type(base_class.__name__, (cls, base_class, BusinessProcess), {}) # XXX-JPS - cls is abbriviatoin - please follow naming conventoin
# here we could inherit many "useful" classes dynamically - héhé
# that would be a "real" abstract composition system
self._effective_model_list = \
orig_self._findEffectiveSpecialiseValueList(portal_type_list)
return self
......@@ -194,4 +202,4 @@ class CompositionMixin:
if model not in model_set]
return model_list
del asComposedDocument
del asComposedDocument # Why ? (hide it ?)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment