Commit c57d5e46 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

rewritten from scratch based on erp5_simulation's experimental PaymentRule.py.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32577 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c9821c5e
...@@ -52,115 +52,44 @@ class PaymentRule(Rule): ...@@ -52,115 +52,44 @@ class PaymentRule(Rule):
receivable_account_type_list = ('asset/receivable', ) receivable_account_type_list = ('asset/receivable', )
payable_account_type_list = ('liability/payable', ) payable_account_type_list = ('liability/payable', )
def _generatePrevisionList(self, applied_rule, **kw):
def _getPaymentConditionList(self, movement):
"""Returns payment conditions for this movement.
""" """
while 1: Generate a list of dictionaries, that contain calculated content of
delivery_movement = movement.getDeliveryValue() current Simulation Movements in applied rule.
if delivery_movement is not None: based on its context (parent movement, delivery, configuration ...)
explanation = delivery_movement.getExplanationValue()
payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition'))
if payment_condition_list:
return payment_condition_list
# 'order' category is deprecated. it is kept for compatibility.
order_movement = movement.getOrderValue()
if order_movement is not None:
explanation = order_movement.getExplanationValue()
payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition'))
if payment_condition_list:
return payment_condition_list
movement = movement.getParentValue().getParentValue() These previsions are returned as dictionaries.
if movement.getPortalType() != self.movement_type:
LOG('ERP5', INFO, "PaymentRule couldn't find payment condition")
return []
def _createMovementsForPaymentCondition(self,
applied_rule, payment_condition):
"""Create simulation movements for this payment condition.
""" """
simulation_movement = applied_rule.getParentValue() prevision_dict_list = []
date = payment_condition.TradeCondition_getDueDate() for input_movement, business_path in self \
._getInputMovementAndPathTupleList(applied_rule):
if payment_condition.getQuantity(): if business_path is None:
quantity = payment_condition.getQuantity() # since Payment Rule does not know what to do without business
else: # path, we return empty list here and creates no simulation
ratio = payment_condition.getEfficiency(1) # movements.
quantity = simulation_movement.getQuantity() * ratio return []
# Since we need to consider business_path only for bank movement,
edit_dict = dict( # not for payable movement, we pass None as business_path here.
causality_value=payment_condition, kw = self._getExpandablePropertyDict(applied_rule, None,
payment_mode=payment_condition.getPaymentMode(), business_path)
source=simulation_movement.getSource(), kw['start_date'] = business_path.getExpectedStartDate(input_movement)
source_section=simulation_movement.getSourceSection(), kw['stop_date'] = business_path.getExpectedStopDate(input_movement)
source_payment=payment_condition.getSourcePayment() or quantity = business_path.getExpectedQuantity(input_movement)
simulation_movement.getSourcePayment(),
destination=simulation_movement.getDestination(), # one for payable
destination_section=simulation_movement.getDestinationSection(), payable_dict = kw.copy()
destination_payment=payment_condition.getDestinationPayment() or payable_dict.update(dict(quanity=-quantity))
simulation_movement.getDestinationPayment(), prevision_dict_list.append(payable_dict)
resource=simulation_movement.getResource(), # one for bank
start_date=date, bank_dict = kw.copy()
price=1, bank_dict.update(dict(quanity=quantity,
quantity= - quantity,) source=business_path.getSource(),
destination=business_path.getDestination()))
applied_rule.newContent( **edit_dict ) prevision_dict_list.append(bank_dict)
return prevision_dict_list
edit_dict['source'] = self.getSourcePayment()
edit_dict['destination'] = self.getDestinationPayment()
edit_dict['quantity'] = - edit_dict['quantity']
applied_rule.newContent( **edit_dict )
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, **kw): def expand(self, applied_rule, **kw):
"""Expands the current movement downward. """Expands the current movement downward.
""" """
my_parent_movement = applied_rule.getParentValue() return Rule._expand(self, applied_rule, **kw)
# generate for source
bank_account = self.getDestinationPaymentValue(
portal_type='Account')
assert bank_account is not None
for payment_condition in self._getPaymentConditionList(
my_parent_movement):
payment_condition_url = payment_condition.getRelativeUrl()
# look for a movement for this payment condition:
corresponding_movement_list = []
for simulation_movement in applied_rule.contentValues():
if simulation_movement.getCausality() == payment_condition_url:
corresponding_movement_list.append(simulation_movement)
if not corresponding_movement_list:
self._createMovementsForPaymentCondition(applied_rule,
payment_condition)
else:
# TODO: update corresponding_movement_list
pass
#Rule.expand(self, applied_rule, **kw)
def test(self, context, tested_base_category_list=None):
"""Test if this rule apply.
"""
# XXX for now disable this rule
return False
if context.getParentValue()\
.getSpecialiseValue().getPortalType() == 'Payment Rule':
return False
for account in ( context.getSourceValue(portal_type='Account'),
context.getDestinationValue(portal_type='Account')):
if account is not None:
account_type = account.getAccountType()
if account_type in self.receivable_account_type_list or \
account_type in self.payable_account_type_list:
return True
return False
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