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