Commit 63f7ead3 authored by Łukasz Nowak's avatar Łukasz Nowak

- use movement_type from Rule class wherever possible

 - remove duplicated variables with same functionality


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28723 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fd3b3c09
...@@ -135,7 +135,7 @@ class AmortisationRule(Rule): ...@@ -135,7 +135,7 @@ class AmortisationRule(Rule):
""" """
def createMovement(property_dict, correction_number): def createMovement(property_dict, correction_number):
new_id = '%s_%i_%i' % (self.movement_name_dict['correction'], aggregated_period_number, correction_number) new_id = '%s_%i_%i' % (self.movement_name_dict['correction'], aggregated_period_number, correction_number)
simulation_movement = applied_rule.newContent(portal_type=delivery_line_type, id=new_id) simulation_movement = applied_rule.newContent(portal_type=self.movement_type, id=new_id)
updateSimulationMovementProperties(simulation_movement = simulation_movement, updateSimulationMovementProperties(simulation_movement = simulation_movement,
calculated_movement = property_dict) calculated_movement = property_dict)
if aggregated_movement['status'] not in invalid_state_list: if aggregated_movement['status'] not in invalid_state_list:
...@@ -267,7 +267,6 @@ class AmortisationRule(Rule): ...@@ -267,7 +267,6 @@ class AmortisationRule(Rule):
### Start of expand() ### ### Start of expand() ###
delivery_line_type = 'Simulation Movement'
to_notify_delivery_list = [] to_notify_delivery_list = []
# Get the item we come from # Get the item we come from
my_item = applied_rule.getCausalityValue() my_item = applied_rule.getCausalityValue()
...@@ -376,7 +375,7 @@ class AmortisationRule(Rule): ...@@ -376,7 +375,7 @@ class AmortisationRule(Rule):
movement = movement_list[movement_number] movement = movement_list[movement_number]
if movement['quantity'] != 0: if movement['quantity'] != 0:
new_id = '%s_%i_%i' % (mov_type, new_period, movement_number) new_id = '%s_%i_%i' % (mov_type, new_period, movement_number)
simulation_movement = applied_rule.newContent(portal_type=delivery_line_type, id=new_id) simulation_movement = applied_rule.newContent(portal_type=self.movement_type, id=new_id)
# Set the properties # Set the properties
updateSimulationMovementProperties(simulation_movement = simulation_movement, updateSimulationMovementProperties(simulation_movement = simulation_movement,
calculated_movement = movement) calculated_movement = movement)
...@@ -418,7 +417,7 @@ class AmortisationRule(Rule): ...@@ -418,7 +417,7 @@ class AmortisationRule(Rule):
else: else:
# No matching found. We simply create the annuity # No matching found. We simply create the annuity
new_id = '%s_%i_%i' % (mov_type, aggregated_period_number, new_aggregated_number) new_id = '%s_%i_%i' % (mov_type, aggregated_period_number, new_aggregated_number)
simulation_movement = applied_rule.newContent(portal_type=delivery_line_type, id=new_id) simulation_movement = applied_rule.newContent(portal_type=self.movement_type, id=new_id)
updateSimulationMovementProperties(simulation_movement = simulation_movement, updateSimulationMovementProperties(simulation_movement = simulation_movement,
calculated_movement = calculated_movement) calculated_movement = calculated_movement)
new_aggregated_number += 1 new_aggregated_number += 1
...@@ -462,7 +461,7 @@ class AmortisationRule(Rule): ...@@ -462,7 +461,7 @@ class AmortisationRule(Rule):
else: else:
# There is no aggregated movement left. We simply create the remaining calculated movements # There is no aggregated movement left. We simply create the remaining calculated movements
new_id = '%s_%i_%i' % (mov_type, aggregated_period_number, new_aggregated_number) new_id = '%s_%i_%i' % (mov_type, aggregated_period_number, new_aggregated_number)
simulation_movement = applied_rule.newContent(portal_type=delivery_line_type, id=new_id) simulation_movement = applied_rule.newContent(portal_type=self.movement_type, id=new_id)
updateSimulationMovementProperties(simulation_movement = simulation_movement, updateSimulationMovementProperties(simulation_movement = simulation_movement,
calculated_movement = calculated_movement) calculated_movement = calculated_movement)
new_aggregated_number += 1 new_aggregated_number += 1
......
...@@ -66,7 +66,6 @@ class DeliveryRule(Rule): ...@@ -66,7 +66,6 @@ class DeliveryRule(Rule):
Rule.expand(self, applied_rule, Rule.expand(self, applied_rule,
delivery_movement_type_list=delivery_movement_type_list, **kw) delivery_movement_type_list=delivery_movement_type_list, **kw)
return return
movement_type = 'Simulation Movement'
existing_movement_list = [] existing_movement_list = []
immutable_movement_list = [] immutable_movement_list = []
delivery = applied_rule.getDefaultCausalityValue() delivery = applied_rule.getDefaultCausalityValue()
...@@ -76,7 +75,7 @@ class DeliveryRule(Rule): ...@@ -76,7 +75,7 @@ class DeliveryRule(Rule):
delivery_movement_list = delivery.getMovementList( delivery_movement_list = delivery.getMovementList(
portal_type=delivery_movement_type_list) portal_type=delivery_movement_type_list)
# Check existing movements # Check existing movements
for movement in applied_rule.contentValues(portal_type=movement_type): for movement in applied_rule.contentValues(portal_type=self.movement_type):
if movement.getLastExpandSimulationState() not in \ if movement.getLastExpandSimulationState() not in \
self.getPortalCurrentInventoryStateList(): self.getPortalCurrentInventoryStateList():
# XXX: This condition is quick and dirty hack - knowing if Simulation # XXX: This condition is quick and dirty hack - knowing if Simulation
...@@ -106,7 +105,7 @@ class DeliveryRule(Rule): ...@@ -106,7 +105,7 @@ class DeliveryRule(Rule):
# Generate the simulation deliv_mvt # Generate the simulation deliv_mvt
# XXX Hardcoded value # XXX Hardcoded value
new_sim_mvt = applied_rule.newContent( new_sim_mvt = applied_rule.newContent(
portal_type=movement_type, portal_type=self.movement_type,
id=new_id, id=new_id,
order_value=deliv_mvt, order_value=deliv_mvt,
order_ratio=1, order_ratio=1,
......
...@@ -66,7 +66,6 @@ class OpenOrderRule(DeliveryRule): ...@@ -66,7 +66,6 @@ class OpenOrderRule(DeliveryRule):
# Delegate implementation of expand to the SubscriptionItem or # Delegate implementation of expand to the SubscriptionItem or
# to the OpenOrder instance # to the OpenOrder instance
return order.expandOpenOrderRule(applied_rule, force=force, **kw) return order.expandOpenOrderRule(applied_rule, force=force, **kw)
movement_type = 'Simulation Movement'
if order is not None: if order is not None:
order_movement_list = order.getMovementList( order_movement_list = order.getMovementList(
portal_type=order.getPortalOrderMovementTypeList()) portal_type=order.getPortalOrderMovementTypeList())
...@@ -89,7 +88,7 @@ class OpenOrderRule(DeliveryRule): ...@@ -89,7 +88,7 @@ class OpenOrderRule(DeliveryRule):
property_dict = self._getExpandablePropertyDict(order_movement, property_dict = self._getExpandablePropertyDict(order_movement,
property_dict) property_dict)
simulation_movement = applied_rule.newContent( simulation_movement = applied_rule.newContent(
portal_type=movement_type, portal_type=self.movement_type,
order_value=order_movement, order_value=order_movement,
order_ratio=1, order_ratio=1,
delivery_ratio=1, delivery_ratio=1,
......
...@@ -66,7 +66,6 @@ class OrderRule(DeliveryRule): ...@@ -66,7 +66,6 @@ class OrderRule(DeliveryRule):
DeliveryRule.expand(self, applied_rule, force=force, **kw) DeliveryRule.expand(self, applied_rule, force=force, **kw)
return return
movement_type = 'Simulation Movement'
existing_movement_list = [] existing_movement_list = []
immutable_movement_list = [] immutable_movement_list = []
order = applied_rule.getDefaultCausalityValue() order = applied_rule.getDefaultCausalityValue()
...@@ -74,7 +73,7 @@ class OrderRule(DeliveryRule): ...@@ -74,7 +73,7 @@ class OrderRule(DeliveryRule):
order_movement_list = order.getMovementList( order_movement_list = order.getMovementList(
portal_type=order.getPortalOrderMovementTypeList()) portal_type=order.getPortalOrderMovementTypeList())
# check existing movements # check existing movements
for movement in applied_rule.contentValues(portal_type=movement_type): for movement in applied_rule.contentValues(portal_type=self.movement_type):
if (not movement.getLastExpandSimulationState() in if (not movement.getLastExpandSimulationState() in
order.getPortalReservedInventoryStateList() and order.getPortalReservedInventoryStateList() and
not movement.getLastExpandSimulationState() in not movement.getLastExpandSimulationState() in
...@@ -109,7 +108,7 @@ class OrderRule(DeliveryRule): ...@@ -109,7 +108,7 @@ class OrderRule(DeliveryRule):
# Do not try to create meaningfull IDs, as order movement can be # Do not try to create meaningfull IDs, as order movement can be
# hierarchicals # hierarchicals
applied_rule.newContent( applied_rule.newContent(
portal_type=movement_type, portal_type=self.movement_type,
order_value=movement, order_value=movement,
order_ratio=1, order_ratio=1,
delivery_ratio=1, delivery_ratio=1,
......
...@@ -76,7 +76,7 @@ class PaymentRule(Rule): ...@@ -76,7 +76,7 @@ class PaymentRule(Rule):
return payment_condition_list return payment_condition_list
movement = movement.getParentValue().getParentValue() movement = movement.getParentValue().getParentValue()
if movement.getPortalType() != 'Simulation Movement': if movement.getPortalType() != self.movement_type:
LOG('ERP5', INFO, "PaymentRule couldn't find payment condition") LOG('ERP5', INFO, "PaymentRule couldn't find payment condition")
return [] return []
...@@ -121,8 +121,6 @@ class PaymentRule(Rule): ...@@ -121,8 +121,6 @@ class PaymentRule(Rule):
def expand(self, applied_rule, **kw): def expand(self, applied_rule, **kw):
"""Expands the current movement downward. """Expands the current movement downward.
""" """
payment_line_type = 'Simulation Movement'
my_parent_movement = applied_rule.getParentValue() my_parent_movement = applied_rule.getParentValue()
# generate for source # generate for source
bank_account = self.getDestinationPaymentValue( bank_account = self.getDestinationPaymentValue(
......
...@@ -46,7 +46,6 @@ class TaxRule(DeliveryRule): ...@@ -46,7 +46,6 @@ class TaxRule(DeliveryRule):
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw): def expand(self, applied_rule, force=0, **kw):
""" """ """ """
movement_type = 'Simulation Movement'
immutable_movement_list = [] immutable_movement_list = []
parent_simulation_movement = applied_rule.getParentValue() parent_simulation_movement = applied_rule.getParentValue()
...@@ -81,7 +80,7 @@ class TaxRule(DeliveryRule): ...@@ -81,7 +80,7 @@ class TaxRule(DeliveryRule):
if not existing_simulation_movement_list: if not existing_simulation_movement_list:
applied_rule.newContent( applied_rule.newContent(
portal_type=movement_type, portal_type=self.movement_type,
order_value=tax_movement, order_value=tax_movement,
order_ratio=1, order_ratio=1,
delivery_ratio=1, delivery_ratio=1,
......
...@@ -40,6 +40,7 @@ from Products.ERP5.Document.SimulationMovement import SimulationMovement ...@@ -40,6 +40,7 @@ from Products.ERP5.Document.SimulationMovement import SimulationMovement
from Products.ERP5Type.Errors import TransformationRuleError from Products.ERP5Type.Errors import TransformationRuleError
class MovementFactory: class MovementFactory:
movement_type = 'Simulation Movement'
def getRequestList(self): def getRequestList(self):
""" """
return the list of a request which to be used to apply movements return the list of a request which to be used to apply movements
...@@ -65,7 +66,7 @@ class MovementFactory: ...@@ -65,7 +66,7 @@ class MovementFactory:
""" """
movement_dict = {} movement_dict = {}
for movement in applied_rule.objectValues( for movement in applied_rule.objectValues(
portal_type="Simulation Movement"): portal_type=self.movement_type):
key = tuple(sorted(movement.getCausalityList())) key = tuple(sorted(movement.getCausalityList()))
movement_dict[key] = movement movement_dict[key] = movement
...@@ -75,7 +76,7 @@ class MovementFactory: ...@@ -75,7 +76,7 @@ class MovementFactory:
movement = movement_dict.get(key, None) movement = movement_dict.get(key, None)
# when no exist # when no exist
if movement is None: if movement is None:
movement = applied_rule.newContent(portal_type="Simulation Movement") movement = applied_rule.newContent(portal_type=self.movement_type)
# update # update
if movement.isFrozen(): if movement.isFrozen():
self.makeDifferentMovement(movement, **request) self.makeDifferentMovement(movement, **request)
...@@ -98,7 +99,7 @@ class MovementFactory: ...@@ -98,7 +99,7 @@ class MovementFactory:
request['quantity'] = self._requestNetQuantity(request)\ request['quantity'] = self._requestNetQuantity(request)\
- movement.getNetQuantity() - movement.getNetQuantity()
if request['quantity'] != 0: if request['quantity'] != 0:
diff_movement = applied_rule.newContent(portal_type="Simulation Movement") diff_movement = applied_rule.newContent(portal_type=self.movement_type)
diff_movement.edit(**request) diff_movement.edit(**request)
......
...@@ -54,9 +54,6 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule): ...@@ -54,9 +54,6 @@ class TransformationRule(TransformationSourcingRuleMixin, Rule):
zope.interface.implements(interfaces.IPredicate, zope.interface.implements(interfaces.IPredicate,
interfaces.IRule ) interfaces.IRule )
# Class variable
simulation_movement_portal_type = "Simulation Movement"
# Simulation workflow # Simulation workflow
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, **kw): def expand(self, applied_rule, **kw):
......
...@@ -90,7 +90,7 @@ class TransformationSourcingRuleMixin(ExtensionClass.Base): ...@@ -90,7 +90,7 @@ class TransformationSourcingRuleMixin(ExtensionClass.Base):
# Create the movement if it does not exist # Create the movement if it does not exist
if movement is None: if movement is None:
movement = applied_rule.newContent( movement = applied_rule.newContent(
portal_type=self.simulation_movement_portal_type, portal_type=self.movement_type,
id=movement_id, id=movement_id,
activate_kw=activate_kw activate_kw=activate_kw
) )
...@@ -143,9 +143,6 @@ class TransformationSourcingRule(TransformationSourcingRuleMixin, Rule): ...@@ -143,9 +143,6 @@ class TransformationSourcingRule(TransformationSourcingRuleMixin, Rule):
zope.interface.implements(interfaces.IPredicate, zope.interface.implements(interfaces.IPredicate,
interfaces.IRule ) interfaces.IRule )
# Class variable
simulation_movement_portal_type = "Simulation Movement"
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, activate_kw=None,**kw): def expand(self, applied_rule, activate_kw=None,**kw):
""" """
......
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