From 599f79cb18c0b0bb14f38705930c490a4277031d Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Wed, 18 Nov 2015 00:36:11 +0900 Subject: [PATCH] Add hooks before/after edit when migrating Simulation Tree to New Simulation. --- product/ERP5/Document/AppliedRule.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/product/ERP5/Document/AppliedRule.py b/product/ERP5/Document/AppliedRule.py index cc87547a62..07de49c2cd 100644 --- a/product/ERP5/Document/AppliedRule.py +++ b/product/ERP5/Document/AppliedRule.py @@ -170,8 +170,12 @@ class AppliedRule(XMLObject, ExplainableMixin): """ return self.objectValues(portal_type=RuleMixin.movement_type) - def _migrateSimulationTree(self, get_matching_key, - get_original_property_dict, root_rule=None): + def _migrateSimulationTree(self, + get_matching_key, + get_original_property_dict, + root_rule=None, + hook_before_edit=None, + hook_after_edit=None): """Migrate an entire simulation tree in order to use new rules This must be called on a root applied rule, with interaction workflows @@ -348,12 +352,19 @@ class AppliedRule(XMLObject, ExplainableMixin): kw['quantity'] = quantity - old.pop('quantity') if new != old or sm.quantity != quantity: raise NotImplementedError # quantity_unit/efficiency ? - else: - recorded_property_dict.update(new) + recorded_property_dict.update(new) + + if hook_before_edit is not None: + hook_before_edit(rule, old_sm, sm, edit_kw, recorded_property_dict) + if recorded_property_dict: sm._recorded_property_dict = PersistentMapping( recorded_property_dict) sm._edit(**edit_kw) + + if hook_after_edit is not None: + hook_after_edit(rule, old_sm, sm) + old_dict[sm] = old_sm sm = None deleted = old_dict.items() -- 2.30.9