From 575ac18d66512e92b2521a4778fb3cfa1d0cce6a Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Tue, 22 Dec 2009 14:27:41 +0000 Subject: [PATCH] initial implementation of AdoptSolver. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31420 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/AdoptSolver.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/product/ERP5/Document/AdoptSolver.py b/product/ERP5/Document/AdoptSolver.py index cc8c2b88e3..b6da68d98b 100644 --- a/product/ERP5/Document/AdoptSolver.py +++ b/product/ERP5/Document/AdoptSolver.py @@ -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() -- 2.30.9