From 7ab965ec33dc642e0039f8e7ac654279563ee46c Mon Sep 17 00:00:00 2001 From: Klaus Woelfel <klaus@nexedi.com> Date: Fri, 25 Nov 2016 11:16:05 +0000 Subject: [PATCH] composition: Allow to define default models Models with workflow state "default" are only considered in composition if no other valid model is defined. This allows to implement "ingest anything" policy in wendelin. --- product/ERP5/mixin/composition.py | 48 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/product/ERP5/mixin/composition.py b/product/ERP5/mixin/composition.py index ee07411fb1..c40954b7a7 100644 --- a/product/ERP5/mixin/composition.py +++ b/product/ERP5/mixin/composition.py @@ -54,28 +54,36 @@ def _getEffectiveModel(self, start_date, stop_date): if not reference: return self - query_list = [Query(reference=reference), - Query(portal_type=self.getPortalType()), - Query(validation_state=('deleted', 'invalidated'), + def get_model_list(excluded_validation_state_list): + query_list = [Query(reference=reference), + Query(portal_type=self.getPortalType()), + Query(validation_state=excluded_validation_state_list, operator='NOT')] - if start_date is not None: - query_list.append(ComplexQuery(Query(effective_date=None), - Query(effective_date=start_date, + if start_date is not None: + query_list.append(ComplexQuery(Query(effective_date=None), + Query(effective_date=start_date, range='<='), - logical_operator='OR')) - if stop_date is not None: - query_list.append(ComplexQuery(Query(expiration_date=None), - Query(expiration_date=stop_date, - range='>'), - logical_operator='OR')) - - # XXX What to do the catalog returns nothing (either because 'self' was just - # created and not yet indexed, or because it was invalidated) ? - # For the moment, we return self if self is invalidated and we raise otherwise. - # This way, if this happens in activity it may succeed when activity is retried. - model_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults( - query=ComplexQuery(logical_operator='AND', *query_list), - sort_on=(('version', 'descending'),)) + logical_operator='OR')) + if stop_date is not None: + query_list.append(ComplexQuery(Query(expiration_date=None), + Query(expiration_date=stop_date, + range='>'), + logical_operator='OR')) + + # XXX What to do the catalog returns nothing (either because 'self' was just + # created and not yet indexed, or because it was invalidated) ? + # For the moment, we return self if self is invalidated and we raise otherwise. + # This way, if this happens in activity it may succeed when activity is retried. + return self.getPortalObject().portal_catalog.unrestrictedSearchResults( + query=ComplexQuery(logical_operator='AND', *query_list), + sort_on=(('version', 'descending'),)) + + # Only include default model if no other valid model found + model_list = get_model_list( + excluded_validation_state_list=('deleted', 'invalidated', 'default')) + if not model_list: + model_list = get_model_list( + excluded_validation_state_list=('deleted', 'invalidated')) if not model_list: if self.getValidationState() == 'invalidated': return self -- 2.30.9