Commit cc164f92 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

merge _getCompensatedMovementListBPM() and _getCompensatedMovementList() still...

merge _getCompensatedMovementListBPM() and _getCompensatedMovementList() still keeping their current behaviours.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35805 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 517b16e8
......@@ -361,11 +361,13 @@ class Rule(Predicate, XMLObject):
return input_movement_and_path_list
def _getCompensatedMovementListBPM(self, applied_rule, **kw):
def _getCompensatedMovementList(self, applied_rule,
matching_property_list=None, **kw):
"""Compute the difference between prevision and existing movements
Immutable movements need compensation, mutable ones needs to be modified
"""
is_bpm = self._isBPM()
add_list = [] # list of movements to be added
modify_dict = {} # dict of movements to be modified
delete_list = [] # list of movements to be deleted
......@@ -378,10 +380,13 @@ class Rule(Predicate, XMLObject):
+ deletable_movement_list
non_matched_list = movement_list[:] # list of remaining movements
if matching_property_list is None:
matching_property_list = self.getMatchingPropertyList()
for prevision in prevision_list:
p_matched_list = []
for movement in non_matched_list:
for prop in self.getMatchingPropertyList():
for prop in matching_property_list:
if movement.isPropertyRecorded(prop):
movement_value = movement.getRecordedProperty(prop)
else:
......@@ -414,13 +419,19 @@ class Rule(Predicate, XMLObject):
break
else:
# no modifiable movement was found, need to compensate by quantity
raise NotImplementedError('Need to generate quantity compensation in %s, because all matched movements are immutable : %r.' % (applied_rule.getRelativeUrl(), [x.getRelativeUrl() for x in p_matched_list]))
if is_bpm:
raise NotImplementedError('Need to generate quantity compensation in %s, because all matched movements are immutable : %r.' % (applied_rule.getRelativeUrl(), [x.getRelativeUrl() for x in p_matched_list]))
else:
prevision['quantity'] = q_diff
add_list.append(prevision)
for movement in p_matched_list:
if movement in (mutable_movement_list \
+ deletable_movement_list):
prop_dict = modify_dict.setdefault(movement.getId(), {})
for k, v in prevision.items():
if k in ('quantity',):
pass
if movement.isPropertyRecorded(k):
movement_value = movement.getRecordedProperty(k)
if isinstance(movement_value, list) and not isinstance(v, list):
......@@ -430,7 +441,7 @@ class Rule(Predicate, XMLObject):
movement_value = None
else:
movement_value = movement.getProperty(k)
if k not in ('quantity',) and v != movement_value:
if v != movement_value:
prop_dict.setdefault(k, v)
# update movement lists
......@@ -458,129 +469,6 @@ class Rule(Predicate, XMLObject):
return (add_list, modify_dict, delete_list)
def _getCompensatedMovementList(self, applied_rule,
matching_property_list=None, **kw):
"""
Compute the difference between prevision and existing movements
immutable movements need compensation, mutables needs to be modified
XXX For now, this implementation is too simple. It could be improved by
using MovementGroups
"""
if self._isBPM():
return self._getCompensatedMovementListBPM(applied_rule, **kw)
add_list = [] # list of movements to be added
modify_dict = {} # dict of movements to be modified
delete_list = [] # list of movements to be deleted
prevision_list = self._generatePrevisionList(applied_rule, **kw)
immutable_movement_list, mutable_movement_list, \
deletable_movement_list = self._getCurrentMovementList(applied_rule,
**kw)
movement_list = immutable_movement_list + mutable_movement_list \
+ deletable_movement_list
non_matched_list = movement_list[:] # list of remaining movements
if matching_property_list is None:
matching_property_list = self.getMatchingPropertyList()
for prevision in prevision_list:
p_matched_list = []
for movement in non_matched_list:
for prop in matching_property_list:
if movement.isPropertyRecorded(prop):
movement_value = movement.getRecordedProperty(prop)
else:
movement_value = movement.getProperty(prop)
if prevision.get(prop) != movement_value:
break
else:
p_matched_list.append(movement)
# XXX hardcoded ...
# LOG("Rule, _getCompensatedMovementList", WARNING,
# "Hardcoded properties check")
# Movements exist, we'll try to make them match the prevision
if p_matched_list != []:
# Check the quantity
m_quantity = 0.0
for movement in p_matched_list:
if movement.isPropertyRecorded('quantity'):
m_quantity += movement.getRecordedProperty('quantity')
else:
m_quantity += movement.getQuantity()
if m_quantity != prevision.get('quantity'):
q_diff = prevision.get('quantity') - m_quantity
# try to find a movement that can be edited
for movement in p_matched_list:
if movement in (mutable_movement_list \
+ deletable_movement_list):
# mark as requiring modification
prop_dict = modify_dict.setdefault(movement.getId(), {})
#prop_dict['quantity'] = movement.getCorrectedQuantity() + \
prop_dict['quantity'] = movement.getQuantity() + \
q_diff
break
# no modifiable movement was found, need to create one
else:
prevision['quantity'] = q_diff
add_list.append(prevision)
# Check the date
for movement in p_matched_list:
if movement in (mutable_movement_list \
+ deletable_movement_list):
prop_dict = modify_dict.setdefault(movement.getId(), {})
for prop in ('start_date', 'stop_date'):
#XXX should be >= 15
if movement.isPropertyRecorded(prop):
movement_value = movement.getRecordedProperty(prop)
else:
movement_value = movement.getProperty(prop)
if prevision.get(prop) != movement_value:
prop_dict[prop] = prevision.get(prop)
break
for k, v in prevision.items():
if k not in ('quantity', 'start_date', 'stop_date'):
if movement.isPropertyRecorded(k):
movement_value = movement.getRecordedProperty(k)
if isinstance(movement_value, list) and not isinstance(v, list):
try:
movement_value = movement_value[0]
except IndexError:
movement_value = None
else:
movement_value = movement.getProperty(k)
if v != movement_value:
prop_dict.setdefault(k, v)
# update movement lists
for movement in p_matched_list:
non_matched_list.remove(movement)
# No movement matched, we need to create one
else:
add_list.append(prevision)
# delete non matched movements
for movement in non_matched_list:
if movement in deletable_movement_list:
# delete movement
delete_list.append(movement.getId())
elif movement in mutable_movement_list:
# set movement quantity to 0 to make it "void"
prop_dict = modify_dict.setdefault(movement.getId(), {})
prop_dict['quantity'] = 0.0
else:
# movement not modifiable, we can decide to create a compensation
# with negative quantity
raise NotImplementedError(
"Can not create a compensation movement for %s" % \
movement.getRelativeUrl())
return (add_list, modify_dict, delete_list)
def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None,
**kw):
"""
......
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