Commit 575ac18d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

initial implementation of AdoptSolver.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31420 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fe6a8f4f
......@@ -59,3 +59,30 @@ class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
zope.interface.implements(interfaces.ISolver,
interfaces.IConfigurable,
)
# ISolver Implementation
def solve(self):
"""
Adopt new property to movements or deliveries.
"""
solved_property = self._getPortalTypeValue().getTestedProperty()
for movement in self.getDeliveryValueList():
# XXX hardcoded
if solved_property == 'quantity':
total_quantity = sum(
[x.getQuantity() for x in movement.getDeliveryRelatedValueList()])
movement.setQuantity(total_quantity)
for simulation_movement in movement.getDeliveryRelatedValueList():
quantity = simulation_movement.getQuantity()
delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity
simulation_movement.edit(delivery_ratio=delivery_ratio,
delivery_error=delivery_error)
else:
# XXX TODO we need to support multiple values for categories or
# list type property.
simulation_movement = movement.getDeliveryRelatedValue()
movement.setProperty(solved_property,
simulation_movement.getProperty(solved_property))
# Finish solving
self.succeed()
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