Commit 288bf89e authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support mapped value in simulation movements by builders. same for divergence...

support mapped value in simulation movements by builders. same for divergence testers will be implemented soon.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33309 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 23fd0a49
......@@ -40,9 +40,10 @@ class CategoryMovementGroup(PropertyMovementGroup):
def _getPropertyDict(self, movement, **kw):
property_dict = {}
getProperty = movement.getMappedProperty
for prop in self.getTestedPropertyList():
property_dict['%s_list' % prop] = sorted(
movement.getPropertyList(prop))
list_prop = '%s_list' % prop
property_dict[list_prop] = sorted(getProperty(list_prop))
return property_dict
def test(self, document, property_dict, property_list=None, **kw):
......
......@@ -312,11 +312,13 @@ class DeliveryBuilder(OrderBuilder):
[s_m]
for s_m_list_per_movement in delivery_dict.values():
total_quantity = sum([quantity_dict.get(s_m, s_m.getQuantity()) \
total_quantity = sum([quantity_dict.get(s_m,
s_m.getMappedProperty('quantity')) \
for s_m in s_m_list_per_movement])
if total_quantity != 0.0:
for s_m in s_m_list_per_movement:
delivery_ratio = quantity_dict.get(s_m, s_m.getQuantity()) \
delivery_ratio = quantity_dict.get(s_m,
s_m.getMappedProperty('quantity')) \
/ total_quantity
s_m.edit(delivery_ratio=delivery_ratio)
else:
......
......@@ -666,7 +666,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
if not update_existing_movement or force_update:
# Now, only 1 movement is possible, so copy from this movement
# XXX hardcoded value
property_dict['quantity'] = simulation_movement.getQuantity()
property_dict['quantity'] = simulation_movement.getMappedProperty('quantity')
property_dict['price'] = simulation_movement.getPrice()
# Update properties on object (quantity, price...)
delivery_movement._edit(force_update=1, **property_dict)
......
......@@ -40,8 +40,9 @@ class PropertyMovementGroup(MovementGroup):
def _getPropertyDict(self, movement, **kw):
property_dict = {}
getProperty = movement.getMappedProperty
for prop in self.getTestedPropertyList():
property_dict[prop] = movement.getProperty(prop, None)
property_dict[prop] = getProperty(prop)
return property_dict
def test(self, document, property_dict, property_list=None, **kw):
......
......@@ -609,3 +609,12 @@ class SimulationMovement(Movement, PropertyRecordableMixin):
movement -- not applicable
"""
raise NotImplementedError
security.declareProtected(Permissions.AccessContentsInformation,
'getMappedProperty')
def getMappedProperty(self, property):
mapping = self.getMappingValue()
if mapping is not None:
return mapping.getMappedProperty(self, property)
else:
return self.getProperty(property)
......@@ -354,11 +354,11 @@ class FakeMovement:
"""
total_quantity = 0
for movement in self.__movement_list:
total_quantity += movement.getQuantity()
total_quantity += movement.getMappedProperty('quantity')
if total_quantity != 0:
for movement in self.__movement_list:
quantity = movement.getQuantity()
quantity = movement.getMappedProperty('quantity')
movement.edit(delivery_ratio=quantity*delivery_ratio/total_quantity)
else:
# Distribute equally ratio to all movement
......@@ -407,7 +407,7 @@ class FakeMovement:
"""
total_quantity = 0
for movement in self.getMovementList():
quantity = movement.getQuantity()
quantity = movement.getMappedProperty('quantity')
if quantity != None:
total_quantity += quantity
return total_quantity
......@@ -418,7 +418,7 @@ class FakeMovement:
"""
total_price = 0
for movement in self.getMovementList():
quantity = movement.getQuantity()
quantity = movement.getMappedProperty('quantity')
price = movement.getPrice()
if (quantity is not None) and (price is not None):
total_price += (quantity * price)
......
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