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,115 +361,13 @@ class Rule(Predicate, XMLObject): ...@@ -361,115 +361,13 @@ class Rule(Predicate, XMLObject):
return input_movement_and_path_list return input_movement_and_path_list
def _getCompensatedMovementListBPM(self, applied_rule, **kw):
"""Compute the difference between prevision and existing movements
Immutable movements need compensation, mutable ones needs to be modified
"""
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
for prevision in prevision_list:
p_matched_list = []
for movement in non_matched_list:
for prop in self.getMatchingPropertyList():
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)
# 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'):
# special case - 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.getQuantity() + \
q_diff
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]))
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 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 k not in ('quantity',) and 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("Tried to delete immutable movement %s" % \
movement.getRelativeUrl())
return (add_list, modify_dict, delete_list)
def _getCompensatedMovementList(self, applied_rule, def _getCompensatedMovementList(self, applied_rule,
matching_property_list=None, **kw): matching_property_list=None, **kw):
""" """Compute the difference between prevision and existing movements
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 Immutable movements need compensation, mutable ones needs to be modified
using MovementGroups
""" """
if self._isBPM(): is_bpm = self._isBPM()
return self._getCompensatedMovementListBPM(applied_rule, **kw)
add_list = [] # list of movements to be added add_list = [] # list of movements to be added
modify_dict = {} # dict of movements to be modified modify_dict = {} # dict of movements to be modified
delete_list = [] # list of movements to be deleted delete_list = [] # list of movements to be deleted
...@@ -498,9 +396,6 @@ class Rule(Predicate, XMLObject): ...@@ -498,9 +396,6 @@ class Rule(Predicate, XMLObject):
else: else:
p_matched_list.append(movement) 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 # Movements exist, we'll try to make them match the prevision
if p_matched_list != []: if p_matched_list != []:
# Check the quantity # Check the quantity
...@@ -511,6 +406,7 @@ class Rule(Predicate, XMLObject): ...@@ -511,6 +406,7 @@ class Rule(Predicate, XMLObject):
else: else:
m_quantity += movement.getQuantity() m_quantity += movement.getQuantity()
if m_quantity != prevision.get('quantity'): if m_quantity != prevision.get('quantity'):
# special case - quantity
q_diff = prevision.get('quantity') - m_quantity q_diff = prevision.get('quantity') - m_quantity
# try to find a movement that can be edited # try to find a movement that can be edited
for movement in p_matched_list: for movement in p_matched_list:
...@@ -518,32 +414,24 @@ class Rule(Predicate, XMLObject): ...@@ -518,32 +414,24 @@ class Rule(Predicate, XMLObject):
+ deletable_movement_list): + deletable_movement_list):
# mark as requiring modification # mark as requiring modification
prop_dict = modify_dict.setdefault(movement.getId(), {}) prop_dict = modify_dict.setdefault(movement.getId(), {})
#prop_dict['quantity'] = movement.getCorrectedQuantity() + \
prop_dict['quantity'] = movement.getQuantity() + \ prop_dict['quantity'] = movement.getQuantity() + \
q_diff q_diff
break break
# no modifiable movement was found, need to create one else:
# no modifiable movement was found, need to compensate by quantity
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: else:
prevision['quantity'] = q_diff prevision['quantity'] = q_diff
add_list.append(prevision) add_list.append(prevision)
# Check the date
for movement in p_matched_list: for movement in p_matched_list:
if movement in (mutable_movement_list \ if movement in (mutable_movement_list \
+ deletable_movement_list): + deletable_movement_list):
prop_dict = modify_dict.setdefault(movement.getId(), {}) 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(): for k, v in prevision.items():
if k not in ('quantity', 'start_date', 'stop_date'): if k in ('quantity',):
pass
if movement.isPropertyRecorded(k): if movement.isPropertyRecorded(k):
movement_value = movement.getRecordedProperty(k) movement_value = movement.getRecordedProperty(k)
if isinstance(movement_value, list) and not isinstance(v, list): if isinstance(movement_value, list) and not isinstance(v, list):
...@@ -576,9 +464,9 @@ class Rule(Predicate, XMLObject): ...@@ -576,9 +464,9 @@ class Rule(Predicate, XMLObject):
else: else:
# movement not modifiable, we can decide to create a compensation # movement not modifiable, we can decide to create a compensation
# with negative quantity # with negative quantity
raise NotImplementedError( raise NotImplementedError("Tried to delete immutable movement %s" % \
"Can not create a compensation movement for %s" % \
movement.getRelativeUrl()) movement.getRelativeUrl())
return (add_list, modify_dict, delete_list) return (add_list, modify_dict, delete_list)
def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None, def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None,
......
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