Commit 1ed303db authored by Romain Courteaud's avatar Romain Courteaud

Initial revision.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3422 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9b9c75c3
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.Rule import Rule
from Products.ERP5.Document.OrderRule import OrderRule
from Products.ERP5.Document.TransformationSourcingRule import\
TransformationSourcingRuleMixin
from zLOG import LOG
class ProductionOrderRule(OrderRule):
"""
Prouction Order Rule object use a Supply Chain to expand a
Production Order.
"""
# CMF Type Definition
meta_type = 'ERP5 Production Order Rule'
portal_type = 'Production Order Rule'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.View)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
)
# Simulation workflow
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
"""
Expands the current movement downward.
-> new status -> expanded
An applied rule can be expanded only if its parent movement
is expanded.
"""
supply_chain = self.getSupplyChain(applied_rule)
# We got a supply chain
# Try to get the last SupplyLink
last_link = supply_chain.getLastLink()
# We got a valid industrial_phase
# Now, we have to generate Simulation Movement, in order to
# create a ProductionPackingList.
destination_node = last_link.getDestinationValue()
source_value = destination_node.getDestinationValue()
source_section_value = last_link.getDestinationSectionValue()
if source_value is not None:
kw["source_value"] = source_value
if source_section_value is not None:
kw["source_section_value"] = source_section_value
# Pass to base class
OrderRule.expand(self, applied_rule, force=force, **kw)
from Products.ERP5Type.Utils import monkeyPatch
monkeyPatch(TransformationSourcingRuleMixin, ProductionOrderRule)
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Globals import InitializeClass, PersistentMapping
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowMethod
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Path import Path
from zLOG import LOG
class SupplyChain(Path, XMLObject):
"""
SupplyChain defines the route used to produced a resource.
"""
# CMF Type Definition
meta_type = 'ERP5 Supply Chain'
portal_type = 'Supply Chain'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.View)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Task
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.Delivery
, PropertySheet.Path
, PropertySheet.FlowCapacity
)
# Class variable
supply_link_portal_type="Supply Link"
security.declareProtected(Permissions.View, 'getLastLink')
def getLastLink(self):
"""
Return the SupplyLink representing the last ridge of the
SupplyChain (if this one is correctly defined...).
"""
# Result value
result = None
# Get all lines.
supply_link_list = self.objectValues(
portal_type=self.supply_link_portal_type)
# Last line is defined by deliverable=1
last_supply_link_list = [x for x in supply_link_list if\
x.getDeliverable()]
# Check if user did not define multiple last links
last_list_len = len(last_supply_link_list)
if (last_list_len == 1):
result = last_supply_link_list[0]
else:
raise "SupplyChainError",\
"Unable to get the last link of SupplyChain %s" %\
str(self.getRelativeUrl())
return result
def getPreviousSupplyLinkList(self, current_supply_link):
"""
Return the previous SupplyLink list.
"""
if current_supply_link is not None:
# Get all SupplyLink in the SupplyChain
supply_link_list = self.objectValues(
portal_type=self.supply_link_portal_type)
# Destination of valid link must be the source of the current link.
current_node_value = current_supply_link.getCurrentNodeValue()
previous_supply_link_list = [
x for x in supply_link_list if\
x.getDestinationValue() == current_node_value]
# Prevent infinite loop
if current_supply_link in previous_supply_link_list:
previous_supply_link_list.remove(current_supply_link)
# Get only production node in the list, or return the entire list
previous_production_list = [x for x in previous_supply_link_list\
if x.isProductionSupplyLink()]
if previous_production_list != []:
previous_supply_link_list = previous_production_list
else:
# No current_supply_link defined, we need to return the last SupplyLink
previous_supply_link_list = [self.getLastLink()]
# Return result
return previous_supply_link_list
security.declareProtected(Permissions.View,
'getPreviousProductionSupplyLinkList')
def getPreviousProductionSupplyLinkList(self, current_supply_link,
recursive=0,
checked_link_list=None):
"""
Return the previous SupplyLink which represents a production.
If recursive=1, browse the SupplyChain until a valid link is found.
checked_link_list is used to prevent infinite loop.
"""
# Initialize checked_link_list parameter...
if checked_link_list is None:
checked_link_list = []
# Checked if we already tested this link
# to prevent infinite loop
if current_supply_link in checked_link_list:
raise "SupplyChainLoop",\
"SupplyLink %r is in a loop." % current_supply_link
else:
transformation_link_list = []
checked_link_list.append(current_supply_link)
# Get the previous link list
previous_link_list = self.getPreviousSupplyLinkList(current_supply_link)
# Test each link
for previous_link in previous_link_list:
# Great, we find a valid one
if previous_link.isProductionSupplyLink():
transformation_link_list.append(previous_link)
# Prevent infinite loop when 2 production_link have the same
# destination
if current_supply_link.isProductionSupplyLink():
raise "SupplyChainError",\
"Those SupplyLinks are in conflict: %r and %r" %\
(current_supply_link.getRelativeUrl(),\
previous_link.getRelativeUrl())
# Reject the current
elif (recursive==1):
# Browse the previous link
transformation_link_list.extend(
self.getPreviousProductionSupplyLinkList(
previous_link,
recursive=recursive,
checked_link_list=checked_link_list))
# Return result
return transformation_link_list
security.declareProtected(Permissions.View,
'getPreviousPackingListSupplyLinkList')
def getPreviousPackingListSupplyLinkList(self, current_supply_link,
recursive=0,
checked_link_list=None,
movement=None):
"""
Return the previous SupplyLink which represents a production.
If recursive=1, browse the SupplyChain until a valid link is found.
checked_link_list is used to prevent infinite loop.
"""
# Initialize checked_link_list parameter...
if checked_link_list is None:
checked_link_list = []
# Checked if we already tested this link
# to prevent infinite loop
if current_supply_link in checked_link_list:
raise "SupplyChainLoop",\
"SupplyLink %r is in a loop." % current_supply_link
else:
packing_list_link_list = []
checked_link_list.append(current_supply_link)
# Get the previous link list
previous_link_list = self.getPreviousSupplyLinkList(current_supply_link)
# Test each link
for previous_link in previous_link_list:
concurrent_list = previous_link_list[:]
concurrent_list.remove(previous_link)
# Great, we find a valid one
if previous_link.isPackingListSupplyLink():
if (movement is None) or\
(previous_link.test(movement, concurrent_list)):
packing_list_link_list.append(previous_link)
# Browse the previous link
if (recursive==1):
packing_list_link_list.extend(
self.getPreviousPackingListSupplyLinkList(
previous_link,
recursive=recursive,
checked_link_list=checked_link_list))
# Return result
return packing_list_link_list
def getPreviousIndustrialPhaseList(self, current_supply_link, method_id,
include_current=0):
"""
Return recursively all previous industrial phase.
"""
method = getattr(self, method_id)
previous_supply_link_list = method(current_supply_link, recursive=1)
# Add the current industrial phase
if (include_current == 1):
previous_supply_link_list.append(current_supply_link)
# Generate the industrial phase list, and remove double
ind_phase_dict = {}
for supply_link in previous_supply_link_list:
ind_phase_value_list = supply_link.getIndustrialPhaseValueList()
if len(ind_phase_value_list) > 1:
# XXX FIXME
raise "SupplyChainError",\
"More than 1 industrial phase can not yet be defined on %r"\
% supply_link
for ind_phase in ind_phase_value_list:
ind_phase_dict[ind_phase] = 1
# Remove None value, and generate the list
ind_phase_dict.pop(None, None)
ind_phase_list = ind_phase_dict.keys()
return ind_phase_list
security.declareProtected(Permissions.View,
'getPreviousProductionIndustrialPhaseList')
def getPreviousProductionIndustrialPhaseList(self, current_supply_link):
"""
Return recursively all previous industrial phase representing
a production.
"""
return self.getPreviousIndustrialPhaseList(
current_supply_link,
"getPreviousProductionSupplyLinkList")
security.declareProtected(Permissions.View,
'getPreviousPackingListIndustrialPhaseList')
def getPreviousPackingListIndustrialPhaseList(self, current_supply_link):
"""
Return recursively all previous industrial phase representing
a packing list.
"""
return self.getPreviousIndustrialPhaseList(
current_supply_link,
"getPreviousPackingListSupplyLinkList",
include_current=1)
# XXX not well implemented (testing)
security.declareProtected(Permissions.View,
'test')
def test(self, current_supply_link, movement):
"""
Test if the resource on the movement can be delivered by
the previous supply link of the current one.
"""
result = 0
previous_packing_link_list = self.\
getPreviousPackingListSupplyLinkList(current_supply_link)
for previous_supply_link in previous_packing_link_list:
concurrent_list = previous_packing_link_list[:]
concurrent_list.remove(previous_supply_link)
if previous_supply_link.test(movement, concurrent_list):
result = 1
break
return result
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability 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
# garantees 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Globals import InitializeClass, PersistentMapping
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLMatrix import XMLMatrix
from Products.ERP5.Document.DeliveryLine import DeliveryLine
from Products.ERP5.Document.Movement import Movement
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Path import Path
from zLOG import LOG
class SupplyLink(Path, XMLObject):
"""
A DeliveryLine object allows to implement lines in
Deliveries (packing list, order, invoice, etc.)
It may include a price (for insurance, for customs, for invoices,
for orders)
"""
meta_type = 'ERP5 Supply Link'
portal_type = 'Supply Link'
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.View)
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.Amount
, PropertySheet.Task
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.Price
, PropertySheet.VariationRange
, PropertySheet.Path
, PropertySheet.FlowCapacity
, PropertySheet.TransformedResource
, PropertySheet.Delivery
, PropertySheet.Simulation
)
security.declareProtected(Permissions.View, 'isProductionSupplyLink')
def isProductionSupplyLink(self):
"""
Return 1 if the SupplyLink represents a production.
"""
return (self.getSourceValue() is None)
security.declareProtected(Permissions.View, 'isPackingListSupplyLink')
def isPackingListSupplyLink(self):
"""
Return 1 if the SupplyLink represents a packing list.
"""
return not(self.isProductionSupplyLink())
security.declareProtected(Permissions.View, 'getCurrentNodeValue')
def getCurrentNodeValue(self):
"""
Return the node used to find the previous SupplyLink
"""
if self.isProductionSupplyLink():
node = self.getDestinationValue()
else:
node = self.getSourceValue()
return node
security.declareProtected(Permissions.View, 'test')
def test(self, movement, concurrent_supply_link_list):
"""
Test if the current link can expand this movement.
Futur implementation have to return properties value
(like quantity) calculated.
"""
# XXX This method has to be rewritten.
# Predicate must be used.
# Current implementation is enough now for customers.
result = 0
resource = movement.getResource()
if resource.find('operation/') == -1:
# XXX reject operation
if concurrent_supply_link_list == []:
result = 1
else:
# Test if the movement correspond to the resource to produced
ind_phase = movement.getIndustrialPhaseValue()
if ind_phase is not None:
# Is this SupplyLink in the route to the previous production node ?
supply_chain = self.getParent()
previous_ind_phase_list =\
supply_chain.getPreviousProductionIndustrialPhaseList(self)
if ind_phase in previous_ind_phase_list:
result = 1
else:
# How to delivered raw materials ?
# First dirty implementation...
if len(concurrent_supply_link_list) > 1:
raise "SupplyChainError",\
"SupplyChain unable to find route."
else:
supply_chain = self.getParent()
previous_ind_phase_list =\
supply_chain.getPreviousProductionIndustrialPhaseList(self)
if len(previous_ind_phase_list) == 0:
result = 1
return result
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