Commit 705e0beb authored by Julien Muchembled's avatar Julien Muchembled

AppliedRule._checkExpand: add parameters to filter objects + better reporting

parent 831cf1a8
Pipeline #35611 failed with stage
in 0 seconds
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
############################################################################## ##############################################################################
from collections import deque from collections import deque
from difflib import unified_diff
from pprint import pformat
import sys import sys
import transaction import transaction
import zope.interface import zope.interface
...@@ -390,7 +392,7 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -390,7 +392,7 @@ class AppliedRule(XMLObject, ExplainableMixin):
return {k: sum(v.values(), []) for k, v in deleted}, delivery_set return {k: sum(v.values(), []) for k, v in deleted}, delivery_set
simulation_tool._delObject(self.getId()) simulation_tool._delObject(self.getId())
def _checkExpand(self): def _checkExpand(self, ignore_nul_movements=False, filter=None):
"""Check that expand() would not fail nor do major changes to the subobjects """Check that expand() would not fail nor do major changes to the subobjects
Transaction is aborted after 'expand' is called. Transaction is aborted after 'expand' is called.
...@@ -405,12 +407,19 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -405,12 +407,19 @@ class AppliedRule(XMLObject, ExplainableMixin):
while object_list: while object_list:
document = object_list.popleft() document = object_list.popleft()
portal_type = document.getPortalType() portal_type = document.getPortalType()
document_dict = {'portal_type': portal_type} document_dict = {property: document.getProperty(property)
for property_ in property_dict[portal_type]: for property in property_dict[portal_type]}
document_dict[property_] = document.getProperty(property_) if ignore_nul_movements and portal_type == 'Simulation Movement' and \
rule_dict[document.getRelativeUrl()] = document_dict not (document_dict['quantity'] and document.getPrice()):
object_list += document.objectValues() if document.isDeletable():
continue
del document_dict['quantity']
document_dict['portal_type'] = portal_type
if filter is None or filter(initial_rule_dict, document, document_dict):
rule_dict[document.getRelativeUrl()] = document_dict
object_list += document.objectValues()
return rule_dict return rule_dict
initial_rule_dict = None
initial_rule_dict = fillRuleDict() initial_rule_dict = fillRuleDict()
try: try:
self.expand("immediate") self.expand("immediate")
...@@ -420,7 +429,15 @@ class AppliedRule(XMLObject, ExplainableMixin): ...@@ -420,7 +429,15 @@ class AppliedRule(XMLObject, ExplainableMixin):
msg = ''.join(ExceptionFormatter.format_exception(*sys.exc_info())[1:]) msg = ''.join(ExceptionFormatter.format_exception(*sys.exc_info())[1:])
else: else:
final_rule_dict = fillRuleDict() final_rule_dict = fillRuleDict()
msg = "%r != %r" % (initial_rule_dict, final_rule_dict) \ if initial_rule_dict == final_rule_dict:
if initial_rule_dict != final_rule_dict else None msg = None
else:
diff = unified_diff(
pformat(initial_rule_dict, width=1000).splitlines(),
pformat(final_rule_dict, width=1000).splitlines(),
lineterm='')
next(diff)
next(diff)
msg = '\n'.join(diff)
transaction.abort() transaction.abort()
return msg return msg
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