Commit 5a8feed0 authored by Jérome Perrin's avatar Jérome Perrin

Use getParentValue insteand of getParent when accessing the parent object

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6517 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ae1c09f8
......@@ -160,13 +160,15 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
# Call a script on the context
if 'price' in self.getMappedValuePropertyList([]):
if getattr(aq_base(self), 'price', None) is not None:
return getattr(self, 'price') # default returns a price defined by the mapped value
# default returns a price defined by the mapped value
return getattr(self, 'price')
else:
return self.aq_parent.getProperty('price') # Price is acquired
return self.getParentValue().getProperty('price') # Price is acquired
else:
return None
security.declareProtected( Permissions.AccessContentsInformation, 'getQuantity' )
security.declareProtected( Permissions.AccessContentsInformation,
'getQuantity' )
def getQuantity(self):
"""
Returns the quantity if defined on the cell
......@@ -177,10 +179,10 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
if getattr(aq_base(self), 'quantity', None) is not None:
return getattr(self, 'quantity')
else:
return self.aq_parent.getProperty('quantity')
return self.getParentValue().getProperty('quantity')
else:
return self.getParent().getQuantity() # We have acquisition here which me should mimic
# return None
# We have acquisition here which me should mimic
return self.getParentValue().getQuantity()
def _setItemIdList(self, value):
"""
......@@ -191,7 +193,8 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
given_item_id_list = value
item_object_list = []
for item in given_item_id_list :
item_result_list = self.portal_catalog(id = item, portal_type="Piece Tissu")
item_result_list = self.portal_catalog(id = item,
portal_type="Piece Tissu")
if len(item_result_list) == 1 :
try :
object = item_result_list[0].getObject()
......@@ -230,36 +233,35 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
self.setTargetQuantity(quantity)
# security.declareProtected(Permissions.ModifyPortalContent, 'applyTargetSolver')
# def applyTargetSolver(self, solver):
# for my_simulation_movement in self.getDeliveryRelatedValueList(portal_type = 'Simulation Movement'):
# self.portal_simulation.applyTargetSolver(my_simulation_movement, solver)
# Required for indexing
security.declareProtected(Permissions.AccessContentsInformation, 'getInventoriatedQuantity')
security.declareProtected(Permissions.AccessContentsInformation,
'getInventoriatedQuantity')
def getInventoriatedQuantity(self):
"""
"""
return Movement.getInventoriatedQuantity(self)
security.declareProtected(Permissions.AccessContentsInformation, 'getStartDate')
security.declareProtected(Permissions.AccessContentsInformation,
'getStartDate')
def getStartDate(self):
"""
"""
return self._baseGetStartDate()
security.declareProtected(Permissions.AccessContentsInformation, 'getStopDate')
security.declareProtected(Permissions.AccessContentsInformation,
'getStopDate')
def getStopDate(self):
"""
"""
return self._baseGetStopDate()
security.declareProtected(Permissions.AccessContentsInformation, 'getStopDate')
security.declareProtected(Permissions.AccessContentsInformation,
'getRootDeliveryValue')
def getRootDeliveryValue(self):
"""
Returns the root delivery responsible of this cell
"""
return self.getParent().getRootDeliveryValue()
return self.getParentValue().getRootDeliveryValue()
# Simulation Consistency Check
def getSimulationQuantity(self):
......@@ -277,16 +279,20 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
return result[0].quantity
return None
security.declareProtected( Permissions.ModifyPortalContent, 'notifyAfterUpdateRelatedContent' )
def notifyAfterUpdateRelatedContent(self, previous_category_url, new_category_url):
security.declareProtected( Permissions.ModifyPortalContent,
'notifyAfterUpdateRelatedContent' )
def notifyAfterUpdateRelatedContent(self, previous_category_url,
new_category_url):
"""
Membership Crirerions and Category List are same in DeliveryCell
Must update it (or change implementation to remove data duplication)
"""
update_method = self.portal_categories.updateRelatedCategory
predicate_value = self.getPredicateValueList()
new_predicate_value = map(lambda c: update_method(c, previous_category_url, new_category_url), predicate_value)
self._setPredicateValueList(new_predicate_value) # No reindex needed since uid stable
new_predicate_value = map(lambda c: update_method(c,
previous_category_url, new_category_url), predicate_value)
self._setPredicateValueList(new_predicate_value)
# No reindex needed since uid stable
# XXX FIXME: option variation are today not well implemented
# This little hack is needed to make the matrixbox working
......@@ -309,14 +315,16 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
if kw.has_key('item_id_list'):
self._setItemIdList(kw['item_id_list'])
security.declareProtected(Permissions.ModifyPortalContent, 'updateSimulationDeliveryProperties')
security.declareProtected(Permissions.ModifyPortalContent,
'updateSimulationDeliveryProperties')
def updateSimulationDeliveryProperties(self, movement_list = None):
"""
Set properties delivery_ratio and delivery_error for each simulation movement
in movement_list (all movements by default), according to this delivery calculated quantity
Set properties delivery_ratio and delivery_error for each
simulation movement in movement_list (all movements by default),
according to this delivery calculated quantity
"""
parent = self.getParent()
parent = self.getParentValue()
if parent is not None:
parent = parent.getParent()
parent = parent.getParentValue()
if parent is not None:
parent.updateSimulationDeliveryProperties(movement_list, self)
......@@ -84,9 +84,9 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated, ImmobilisationMovem
"""
Explicitly acquire simulation_state from parent
"""
if hasattr(self.getParent(),'getSimulationState'):
return self.getParent().getSimulationState()
return None
method = getattr(self.getParentValue(),'getSimulationState', None)
if method is not None:
return method()
# Force in _edit to modify variation_base_category_list first
security.declarePrivate( '_edit' )
......@@ -383,19 +383,22 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated, ImmobilisationMovem
result = self.DeliveryLine_zGetRelatedDestinationSection(uid=self.getUid())
return map(lambda x: x.destination_section, result)
security.declareProtected(Permissions.AccessContentsInformation, 'getStopDate')
security.declareProtected(Permissions.AccessContentsInformation,
'getRootDeliveryValue')
def getRootDeliveryValue(self):
"""
Returns the root delivery responsible of this line
"""
return self.getParent().getRootDeliveryValue()
return self.getParentValue().getRootDeliveryValue()
security.declareProtected(Permissions.ModifyPortalContent, 'updateSimulationDeliveryProperties')
security.declareProtected(Permissions.ModifyPortalContent,
'updateSimulationDeliveryProperties')
def updateSimulationDeliveryProperties(self, movement_list = None):
"""
Set properties delivery_ratio and delivery_error for each simulation movement
in movement_list (all movements by default), according to this delivery calculated quantity
Set properties delivery_ratio and delivery_error for each
simulation movement in movement_list (all movements by default),
according to this delivery calculated quantity
"""
parent = self.getParent()
parent = self.getParentValue()
if parent is not None:
parent.updateSimulationDeliveryProperties(movement_list, self)
......@@ -214,7 +214,7 @@ class ImmobilisableItem(XMLObject, Amount):
organisation.getFinancialYearStopDate() is None:
if category is None: return None
if category.getPortalType() != "Base Category":
return self._getFirstIndependantOrganisation(category.getParent())
return self._getFirstIndependantOrganisation(category.getParentValue())
else:
return None
return organisation
......
......@@ -137,7 +137,7 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
resource = invoice.getPriceCurrency()
if resource is None :
# search the resource on parents simulation movement's deliveries
simulation_movement = applied_rule.getParent()
simulation_movement = applied_rule.getParentValue()
portal_simulation = self.getPortalObject().portal_simulation
while resource is None and \
simulation_movement != portal_simulation :
......@@ -145,7 +145,7 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
if hasattr(delivery, 'getPriceCurrency') and \
delivery.getPriceCurrency() is not None :
resource = delivery.getPriceCurrency()
if simulation_movement.getParent().getParent() \
if simulation_movement.getParentValue().getParentValue() \
== portal_simulation :
# we are on the first simulation movement, we'll try
# to get the resource from it's order price currency.
......@@ -154,7 +154,7 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
order.getPriceCurrency() is not None :
resource = order.getPriceCurrency()
simulation_movement = simulation_movement\
.getParent().getParent()
.getParentValue().getParentValue()
if resource is None :
# last resort : get the resource from the rule
......
......@@ -64,7 +64,7 @@ class InvoicingRule(Rule):
"""
Tests if the rule (still) applies
"""
parent = movement.getParent()
parent = movement.getParentValue()
result = 0
if (parent.getPortalType() == 'Applied Rule') and \
(parent.getSpecialiseId() in ('default_order_rule',
......@@ -78,9 +78,10 @@ class InvoicingRule(Rule):
"""
delivery_line_type = 'Simulation Movement'
# Source that movement from the next node / stock
my_context_movement = applied_rule.getParent()
my_context_movement = applied_rule.getParentValue()
# Do not invoice within the same entity or whenever entities are not all defined
# Do not invoice within the same entity or whenever entities are
# not all defined
# It is OK to invoice within different entities of the same company
# if we wish to get some internal analytical accounting
# but that requires some processing to produce a balance sheet
......
......@@ -67,7 +67,7 @@ class PaymentRule(Rule):
Tests if the rule (still) applies
"""
if 'receivable' in movement.getId() : ### TODO: expand 'payable' too
parent = movement.getParent()
parent = movement.getParentValue()
if parent.getPortalType()=='Applied Rule' \
and parent.getSpecialiseId()=='default_invoice_transaction_rule':
#LOG('PaymentRule.test :', 0, repr(( 'applies with', movement, parent )))
......@@ -86,7 +86,7 @@ class PaymentRule(Rule):
"""
payment_line_type = 'Simulation Movement'
my_parent_movement = applied_rule.getParent()
my_parent_movement = applied_rule.getParentValue()
if my_parent_movement.getQuantity() is not None:
bank_id = 'bank'
......
......@@ -222,7 +222,7 @@ class SimulationMovement(Movement):
# we know that invoicing rule acts like this, and that it comes after
# invoice or invoicing_rule, so we if we come from invoince rule or
# invoicing rule, we always expand regardless of the causality state.
if ((self.getParent().getSpecialiseId() not in
if ((self.getParentValue().getSpecialiseId() not in
('default_invoicing_rule', 'default_invoice_rule')
and self.getCausalityState() == 'expanded' ) or \
len(self.objectIds()) != 0):
......@@ -336,7 +336,7 @@ class SimulationMovement(Movement):
while explanation_value.getPortalType() not in \
self.getPortalDeliveryTypeList() and \
explanation_value != self.getPortalObject():
explanation_value = explanation_value.getParent()
explanation_value = explanation_value.getParentValue()
if explanation_value != self.getPortalObject():
return explanation_value
......@@ -523,7 +523,7 @@ class SimulationMovement(Movement):
Return the root simulation movement in the simulation tree.
FIXME : this method should be called getRootSimulationMovementValue
"""
parent_applied_rule = self.getParent()
parent_applied_rule = self.getParentValue()
if parent_applied_rule.getRootAppliedRule() == parent_applied_rule:
return self
else:
......
......@@ -122,7 +122,7 @@ class SupplyLink(Path, XMLObject):
ind_phase_list = movement.getIndustrialPhaseValueList()
if ind_phase_list != []:
# Is this SupplyLink in the route to the previous production node ?
supply_chain = self.getParent()
supply_chain = self.getParentValue()
previous_ind_phase_list =\
supply_chain.getPreviousProductionIndustrialPhaseList(self)
for ind_phase in ind_phase_list:
......@@ -139,24 +139,24 @@ class SupplyLink(Path, XMLObject):
else:
# Check if raw material is create by a production link or a packing
# list link.
supply_chain = self.getParent()
supply_chain = self.getParentValue()
next_industrial_phase_list = \
supply_chain.getNextProductionIndustrialPhaseList(self)
ind_phase_id_list = [x.getId() for x in next_industrial_phase_list]
# Get the transformation to use
applied_rule = movement.getParent()
applied_rule = movement.getParentValue()
rule = applied_rule.getSpecialiseValue()
transformation = rule.getTransformation(movement)
# Call getAggregatedAmountList
amount_list = transformation.getAggregatedAmountList(
movement.getParent().getParent(),
movement.getParentValue().getParentValue(),
ind_phase_id_list=ind_phase_id_list)
resource_list = [x.getResourceValue() for x in amount_list]
current_resource = movement.getResourceValue()
if current_resource not in resource_list:
# We can delivered this resource
supply_chain = self.getParent()
supply_chain = self.getParentValue()
previous_ind_phase_list =\
supply_chain.getPreviousProductionIndustrialPhaseList(self)
if len(previous_ind_phase_list) == 0:
......
......@@ -84,7 +84,7 @@ class TransformationRule(Rule):
# We only produced what is asked on the Production Order
result = 0
else:
supply_chain = self.getSupplyChain(movement.getParent())
supply_chain = self.getSupplyChain(movement.getParentValue())
parent_supply_link = self.getCurrentSupplyLink(movement)
current_tranfo_link_list = supply_chain.\
getPreviousProductionSupplyLinkList(parent_supply_link)
......@@ -107,13 +107,13 @@ class TransformationRule(Rule):
An applied rule can be expanded only if its parent movement
is expanded.
"""
parent_movement = applied_rule.getParent()
parent_movement = applied_rule.getParentValue()
# Get production node and production section
production = parent_movement.getSource()
production_section = parent_movement.getSourceSection()
# Get the current supply link used to calculate consumed resource
# The current supply link is calculated from the parent AppliedRule.
supply_chain = self.getSupplyChain(parent_movement.getParent())
supply_chain = self.getSupplyChain(parent_movement.getParentValue())
parent_supply_link = self.getCurrentSupplyLink(parent_movement)
current_supply_link_list = supply_chain.\
getPreviousProductionSupplyLinkList(parent_supply_link)
......@@ -148,7 +148,7 @@ class TransformationRule(Rule):
Create a movement for the resource produced by the transformation.
Only one produced movement can be created.
"""
parent_movement = applied_rule.getParent()
parent_movement = applied_rule.getParentValue()
stop_date = parent_movement.getStartDate()
produced_movement_dict = {
'pr': {
......@@ -183,8 +183,8 @@ class TransformationRule(Rule):
# Store each value in a dictionnary before created them.
# { movement_id: {property_name: property_value,} ,}
consumed_movement_dict = {}
parent_movement = applied_rule.getParent()
supply_chain = self.getSupplyChain(parent_movement.getParent())
parent_movement = applied_rule.getParentValue()
supply_chain = self.getSupplyChain(parent_movement.getParentValue())
# Consumed previous variation
previous_variation_dict = self._expandConsumedPreviousVariation(
applied_rule,
......@@ -211,7 +211,7 @@ class TransformationRule(Rule):
"""
id_count = 1
consumed_movement_dict = {}
parent_movement = applied_rule.getParent()
parent_movement = applied_rule.getParentValue()
# Calculate the variation category list of parent movement
base_category_list = parent_movement.getVariationBaseCategoryList()
if "industrial_phase" in base_category_list:
......@@ -257,7 +257,7 @@ class TransformationRule(Rule):
"""
Create a movement for each resource consumed by the transformation,
"""
parent_movement = applied_rule.getParent()
parent_movement = applied_rule.getParentValue()
# Calculate the context for getAggregatedAmountList
base_category_list = parent_movement.getVariationBaseCategoryList()
if "industrial_phase" in base_category_list:
......
......@@ -104,12 +104,12 @@ class TransformationSourcingRuleMixin(ExtensionClass.Base):
production_order_movement = movement.getRootSimulationMovement().\
getOrderValue()
# XXX Acquisition can be use instead
parent_uid = production_order_movement.getParent().getUid()
parent_uid = production_order_movement.getParentUid()
explanation_uid = production_order_movement.getExplanationUid()
if parent_uid == explanation_uid:
production_order_line = production_order_movement
else:
production_order_line = production_order_movement.getParent()
production_order_line = production_order_movement.getParentValue()
script = production_order_line._getTypeBasedMethod('_getTransformation')
if script is not None:
transformation = script()
......@@ -165,7 +165,7 @@ class TransformationSourcingRule(Rule):
(movement.getSourceValue() is None):
result = 0
else:
supply_chain = self.getSupplyChain(movement.getParent())
supply_chain = self.getSupplyChain(movement.getParentValue())
parent_supply_link = self.getCurrentSupplyLink(movement)
if not supply_chain.test(parent_supply_link, movement):
result = 0
......@@ -191,9 +191,9 @@ class TransformationSourcingRule(Rule):
An applied rule can be expanded only if its parent movement
is expanded.
"""
parent_movement = applied_rule.getParent()
parent_movement = applied_rule.getParentValue()
# Calculate the previous supply link
supply_chain = self.getSupplyChain(parent_movement.getParent())
supply_chain = self.getSupplyChain(parent_movement.getParentValue())
parent_supply_link = self.getCurrentSupplyLink(parent_movement)
previous_supply_link_list = supply_chain.\
getPreviousPackingListSupplyLinkList(
......
......@@ -279,12 +279,12 @@ class CausalityMovementGroup(RootMovementGroup):
def _getExplanationRelativeUrl(self, movement):
""" Get the order value for a movement """
if hasattr(movement, 'getParent'):
if hasattr(movement, 'getParentValue'):
# This is a simulation movement
if movement.getParent() != movement.getRootAppliedRule() :
if movement.getParentValue() != movement.getRootAppliedRule() :
# get the explanation of parent movement if we have not been
# created by the root applied rule.
movement = movement.getParent().getParent()
movement = movement.getParentValue().getParentValue()
explanation_value = movement.getExplanationValue()
if explanation_value is None:
raise ValueError, 'No explanation for movement %s' % movement.getPath()
......@@ -1024,7 +1024,7 @@ class TransformationAppliedRuleCausalityMovementGroup(RootMovementGroup):
def _getExplanationRelativeUrl(self, movement):
""" Get the order value for a movement """
transformation_applied_rule = movement.getParent()
transformation_applied_rule = movement.getParentValue()
transformation_rule = transformation_applied_rule.getSpecialiseValue()
if transformation_rule.getPortalType() != 'Transformation Rule':
raise MovementGroupError, 'movement! %s' % movement.getPath()
......
......@@ -93,8 +93,8 @@ class CopyToTarget(TargetSolver):
"""
Get parent movement, and its value delta dict.
"""
applied_rule = movement.getParent()
parent_movement = applied_rule.getParent()
applied_rule = movement.getParentValue()
parent_movement = applied_rule.getParentValue()
if parent_movement.getPortalType() != "Simulation Movement":
parent_movement = None
return parent_movement, value_delta_dict
......
......@@ -60,7 +60,7 @@ class TransformationSourcingCopyToTarget(CopyToTarget):
"""
Get parent movement, and its value delta dict.
"""
applied_rule = movement.getParent()
applied_rule = movement.getParentValue()
rule = applied_rule.getSpecialiseValue()
if rule.getPortalType() != "Transformation Sourcing Rule":
value_delta_dict.pop('aggregate_list', None)
......
......@@ -773,7 +773,7 @@ class TestAccountingRules(TestAccountingRulesMixin,ERP5TypeTestCase):
# getTotalPrice uses mysql, so we must make sure the invoice is cataloged
# to have correct results
invoice_line.getParent().recursiveImmediateReindexObject()
invoice_line.getParentValue().recursiveImmediateReindexObject()
self.assertEqual(invoice_line.getTotalPrice(), 100)
self.assertEqual(invoice_line.getTotalQuantity(), 10)
......
......@@ -719,7 +719,7 @@ be a problem)."""
object.immediateReindexObject()
if delete:
if len(from_object.portal_categories.getRelatedValueList(from_object))==0:
parent = from_object.getParent()
parent = from_object.getParentValue()
parent.manage_delObjects(from_object.getId())
return corrected_list
......
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