Commit f0c8d94f authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make delivery solvers ERP5 documents.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36862 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9d432b8b
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2008-2009 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential # programmers who take the whole responsibility of assessing all potential
...@@ -23,38 +22,47 @@ ...@@ -23,38 +22,47 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
############################################################################## ##############################################################################
import zope.interface import zope.interface
from Products.ERP5Type import interfaces from AccessControl import ClassSecurityInfo
from DeliverySolver import DeliverySolver from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
class FIFO(DeliverySolver): class FIFODeliverySolver(XMLObject):
""" """
The FIFO solver reduces delivered quantity by reducing the quantity of The FIFO solver reduces delivered quantity by reducing the quantity of
simulation movements from the last order. simulation movements from the last order.
""" """
meta_type = 'ERP5 FIFO Delivery Solver'
portal_type = 'FIFO Delivery Solver'
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative interfaces # Declarative security
zope.interface.implements(interfaces.IDeliverySolver) security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
title = 'FIFO Solver' # Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.DeliverySolver
)
# IDeliverySolver Implementation # Declarative interfaces
def __init__(self, simulation_movement_list): zope.interface.implements(interfaces.IDeliverySolver,)
"""
Move this to mixin
"""
self.simulation_movement_list = simulation_movement_list
# IDeliverySolver Implementation
def getTotalQuantity(self): def getTotalQuantity(self):
""" """
Move this to mixin Move this to mixin
""" """
total_quantity = 0 total_quantity = 0
for movement in self.simulation_movement_list: for movement in self.getDeliveryValueList():
total_quantity += movement.getQuantity() total_quantity += movement.getQuantity()
return total_quantity return total_quantity
...@@ -87,7 +95,7 @@ class FIFO(DeliverySolver): ...@@ -87,7 +95,7 @@ class FIFO(DeliverySolver):
""" """
Returns a list of simulation movement sorted from the last order. Returns a list of simulation movement sorted from the last order.
""" """
simulation_movement_list = self.simulation_movement_list simulation_movement_list = self.getDeliveryValueList()
if len(simulation_movement_list) > 1: if len(simulation_movement_list) > 1:
return sorted(simulation_movement_list, return sorted(simulation_movement_list,
key=lambda x:x.getExplainationValue().getStartDate(), reverse=True) key=lambda x:x.getExplainationValue().getStartDate(), reverse=True)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2008-2009 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential # programmers who take the whole responsibility of assessing all potential
...@@ -23,31 +22,45 @@ ...@@ -23,31 +22,45 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
############################################################################## ##############################################################################
import zope.interface import zope.interface
from Products.ERP5Type import interfaces from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.Document.FIFODeliverySolver import FIFODeliverySolver
from FIFO import FIFO class LIFODeliverySolver(FIFODeliverySolver):
class LIFO(FIFO):
""" """
The LIFO solver reduces delivered quantity by reducing the quantity of The LIFO solver reduces delivered quantity by reducing the quantity of
simulation movements from the first order. simulation movements from the first order.
""" """
meta_type = 'ERP5 LIFO Delivery Solver'
portal_type = 'LIFO Delivery Solver'
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative interfaces # Declarative security
zope.interface.implements(interfaces.IDeliverySolver) security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
title = 'LIFO Solver' # Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.DeliverySolver
)
# Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolver,)
def _getSimulationMovementList(self): def _getSimulationMovementList(self):
""" """
Returns a list of simulation movement sorted from the first order. Returns a list of simulation movement sorted from the first order.
""" """
simulation_movement_list = self.simulation_movement_list simulation_movement_list = self.getDeliveryValueList()
if len(simulation_movement_list) > 1: if len(simulation_movement_list) > 1:
return sorted(simulation_movement_list, return sorted(simulation_movement_list,
key=lambda x:x.getExplainationValue().getStartDate()) key=lambda x:x.getExplainationValue().getStartDate())
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2008-2009 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential # programmers who take the whole responsibility of assessing all potential
...@@ -23,25 +22,41 @@ ...@@ -23,25 +22,41 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
############################################################################## ##############################################################################
import zope.interface import zope.interface
from Products.ERP5Type import interfaces from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.Document.FIFODeliverySolver import FIFODeliverySolver
from FIFO import FIFO class MinimisePriceDeliverySolver(FIFODeliverySolver):
class MinPrice(FIFO):
""" """
The MinPrice deliver solver distributes quantity in order to minimise The Minimise Price deliver solver distributes quantity in order to minimise
price. price.
""" """
# Declarative interfaces meta_type = 'ERP5 Minimise Price Delivery Solver'
zope.interface.implements(interfaces.IDeliverySolver) portal_type = 'Minimise Price Delivery Solver'
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
title = 'MinPrice Solver' # Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.DeliverySolver
)
# Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolver,)
# IDeliverySolver Implementation
def setTotalQuantity(self, new_quantity, activate_kw=None): def setTotalQuantity(self, new_quantity, activate_kw=None):
""" """
""" """
...@@ -73,7 +88,7 @@ class MinPrice(FIFO): ...@@ -73,7 +88,7 @@ class MinPrice(FIFO):
""" """
Returns a list of simulation movement sorted from the lower price. Returns a list of simulation movement sorted from the lower price.
""" """
simulation_movement_list = self.simulation_movement_list simulation_movement_list = self.getDeliveryValueList()
if len(simulation_movement_list) > 1: if len(simulation_movement_list) > 1:
return sorted(simulation_movement_list, key=lambda x:x.getPrice()) return sorted(simulation_movement_list, key=lambda x:x.getPrice())
else: else:
......
...@@ -73,8 +73,10 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -73,8 +73,10 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
[]).append(simulation_movement) []).append(simulation_movement)
for movement, simulation_movement_list in delivery_dict.iteritems(): for movement, simulation_movement_list in delivery_dict.iteritems():
decision_quantity = movement.getQuantity() decision_quantity = movement.getQuantity()
delivery_solver = self.portal_solvers.newDeliverySolver( delivery_solver = self.getParentValue().newContent(
configuration_dict['delivery_solver'], simulation_movement_list) portal_type=configuration_dict['delivery_solver'],
temp_object=True)
delivery_solver.setDeliveryValueList(simulation_movement_list)
# Update the quantity using delivery solver algorithm # Update the quantity using delivery solver algorithm
split_list = delivery_solver.setTotalQuantity(decision_quantity, split_list = delivery_solver.setTotalQuantity(decision_quantity,
activate_kw=activate_kw) activate_kw=activate_kw)
......
...@@ -1118,6 +1118,14 @@ class ERP5Site(FolderMixIn, CMFSite): ...@@ -1118,6 +1118,14 @@ class ERP5Site(FolderMixIn, CMFSite):
""" """
return self._getPortalGroupedTypeList('target_solver') return self._getPortalGroupedTypeList('target_solver')
security.declareProtected(Permissions.AccessContentsInformation,
'getPortalTargetSolverTypeList')
def getPortalDeliverySolverTypeList(self):
"""
Return delivery solver types.
"""
return self._getPortalGroupedTypeList('delivery_solver')
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getPortalAmountGeneratorTypeList') 'getPortalAmountGeneratorTypeList')
def getPortalAmountGeneratorTypeList(self): def getPortalAmountGeneratorTypeList(self):
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
class DeliverySolver:
_categories = ('delivery',)
...@@ -260,7 +260,7 @@ class ERP5TypeInformation(XMLObject, ...@@ -260,7 +260,7 @@ class ERP5TypeInformation(XMLObject,
'recent_document', 'my_document', 'template_document', 'recent_document', 'my_document', 'template_document',
'crawler_index', 'crawler_index',
# Solvers and simulation # Solvers and simulation
'divergence_tester', 'target_solver', 'divergence_tester', 'target_solver', 'delivery_solver',
'amount_generator', 'amount_generator_line', 'amount_generator_cell', 'amount_generator', 'amount_generator_line', 'amount_generator_cell',
# Movement Group # Movement Group
'movement_group', 'movement_group',
......
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