Commit c9821c5e authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

2 spaces indent.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32576 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ac44e693
...@@ -36,131 +36,131 @@ from Products.ERP5.Document.Rule import Rule ...@@ -36,131 +36,131 @@ from Products.ERP5.Document.Rule import Rule
from zLOG import LOG, INFO from zLOG import LOG, INFO
class PaymentRule(Rule): class PaymentRule(Rule):
"""Payment Rule generates payment simulation movement from invoice """Payment Rule generates payment simulation movement from invoice
transaction simulation movements. transaction simulation movements.
""" """
# CMF Type Definition
meta_type = 'ERP5 Payment Rule'
portal_type = 'Payment Rule'
add_permission = Permissions.AddPortalContent
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# CMF Type Definition receivable_account_type_list = ('asset/receivable', )
meta_type = 'ERP5 Payment Rule' payable_account_type_list = ('liability/payable', )
portal_type = 'Payment Rule'
add_permission = Permissions.AddPortalContent
def _getPaymentConditionList(self, movement):
# Declarative security """Returns payment conditions for this movement.
security = ClassSecurityInfo() """
security.declareObjectProtected(Permissions.AccessContentsInformation) while 1:
delivery_movement = movement.getDeliveryValue()
receivable_account_type_list = ('asset/receivable', ) if delivery_movement is not None:
payable_account_type_list = ('liability/payable', ) explanation = delivery_movement.getExplanationValue()
payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition'))
def _getPaymentConditionList(self, movement): if payment_condition_list:
"""Returns payment conditions for this movement. return payment_condition_list
"""
while 1: # 'order' category is deprecated. it is kept for compatibility.
delivery_movement = movement.getDeliveryValue() order_movement = movement.getOrderValue()
if delivery_movement is not None: if order_movement is not None:
explanation = delivery_movement.getExplanationValue() explanation = order_movement.getExplanationValue()
payment_condition_list = explanation.contentValues( payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition')) filter=dict(portal_type='Payment Condition'))
if payment_condition_list: if payment_condition_list:
return payment_condition_list return payment_condition_list
# 'order' category is deprecated. it is kept for compatibility. movement = movement.getParentValue().getParentValue()
order_movement = movement.getOrderValue() if movement.getPortalType() != self.movement_type:
if order_movement is not None: LOG('ERP5', INFO, "PaymentRule couldn't find payment condition")
explanation = order_movement.getExplanationValue() return []
payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition')) def _createMovementsForPaymentCondition(self,
if payment_condition_list: applied_rule, payment_condition):
return payment_condition_list """Create simulation movements for this payment condition.
"""
movement = movement.getParentValue().getParentValue() simulation_movement = applied_rule.getParentValue()
if movement.getPortalType() != self.movement_type: date = payment_condition.TradeCondition_getDueDate()
LOG('ERP5', INFO, "PaymentRule couldn't find payment condition")
return [] if payment_condition.getQuantity():
quantity = payment_condition.getQuantity()
def _createMovementsForPaymentCondition(self, else:
applied_rule, payment_condition): ratio = payment_condition.getEfficiency(1)
"""Create simulation movements for this payment condition. quantity = simulation_movement.getQuantity() * ratio
"""
simulation_movement = applied_rule.getParentValue() edit_dict = dict(
date = payment_condition.TradeCondition_getDueDate() causality_value=payment_condition,
payment_mode=payment_condition.getPaymentMode(),
if payment_condition.getQuantity(): source=simulation_movement.getSource(),
quantity = payment_condition.getQuantity() source_section=simulation_movement.getSourceSection(),
source_payment=payment_condition.getSourcePayment() or
simulation_movement.getSourcePayment(),
destination=simulation_movement.getDestination(),
destination_section=simulation_movement.getDestinationSection(),
destination_payment=payment_condition.getDestinationPayment() or
simulation_movement.getDestinationPayment(),
resource=simulation_movement.getResource(),
start_date=date,
price=1,
quantity= - quantity,)
applied_rule.newContent( **edit_dict )
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')
def expand(self, applied_rule, **kw):
"""Expands the current movement downward.
"""
my_parent_movement = applied_rule.getParentValue()
# 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: else:
ratio = payment_condition.getEfficiency(1) # TODO: update corresponding_movement_list
quantity = simulation_movement.getQuantity() * ratio pass
edit_dict = dict( #Rule.expand(self, applied_rule, **kw)
causality_value=payment_condition,
payment_mode=payment_condition.getPaymentMode(),
source=simulation_movement.getSource(),
source_section=simulation_movement.getSourceSection(),
source_payment=payment_condition.getSourcePayment() or
simulation_movement.getSourcePayment(),
destination=simulation_movement.getDestination(),
destination_section=simulation_movement.getDestinationSection(),
destination_payment=payment_condition.getDestinationPayment() or
simulation_movement.getDestinationPayment(),
resource=simulation_movement.getResource(),
start_date=date,
price=1,
quantity= - quantity,)
applied_rule.newContent( **edit_dict )
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')
def expand(self, applied_rule, **kw):
"""Expands the current movement downward.
"""
my_parent_movement = applied_rule.getParentValue()
# 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()\ def test(self, context, tested_base_category_list=None):
.getSpecialiseValue().getPortalType() == 'Payment Rule': """Test if this rule apply.
return False """
for account in ( context.getSourceValue(portal_type='Account'), # XXX for now disable this rule
context.getDestinationValue(portal_type='Account')): return False
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
if context.getParentValue()\
.getSpecialiseValue().getPortalType() == 'Payment Rule':
return False 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