Commit d11a1feb authored by Jérome Perrin's avatar Jérome Perrin

generate payment transactions from payment conditions (prototype state).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20231 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e5e01b57
No related merge requests found
...@@ -33,14 +33,11 @@ from Products.CMFCore.utils import getToolByName ...@@ -33,14 +33,11 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.Rule import Rule from Products.ERP5.Document.Rule import Rule
from zLOG import LOG 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.
This one is a very s(imple|tupid) one : if the parent movement is a 'receivable' one,
we just create two submovements : 'receivable' (as credit)
and 'bank' (as debit) with the same quantity as the parent.
""" """
# CMF Type Definition # CMF Type Definition
...@@ -65,59 +62,115 @@ class PaymentRule(Rule): ...@@ -65,59 +62,115 @@ class PaymentRule(Rule):
, PropertySheet.Task , PropertySheet.Task
) )
security.declareProtected(Permissions.ModifyPortalContent, 'expand') receivable_account_type_list = ('asset/receivable', )
def expand(self, applied_rule, **kw): payable_account_type_list = ('liability/payable', )
def _getPaymentConditionList(self, movement):
"""Returns payment conditions for this movement.
"""
while 1:
delivery_movement = movement.getDeliveryValue()
if delivery_movement is not None:
explanation = delivery_movement.getExplanationValue()
payment_condition_list = explanation.contentValues(
filter=dict(portal_type='Payment Condition'))
if payment_condition_list:
return payment_condition_list
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()
if movement.getPortalType() != 'Simulation Movement':
LOG('ERP5', INFO, "PaymentRule couldn't find payment condition")
return []
def _createMovementsForPaymentCondition(self,
applied_rule, payment_condition):
"""Create simulation movements for this payment condition.
""" """
Expands the current movement downward. simulation_movement = applied_rule.getParentValue()
date = payment_condition.TradeCondition_getDueDate()
if payment_condition.getQuantity():
quantity = payment_condition.getQuantity()
else:
ratio = payment_condition.getEfficiency(1)
quantity = simulation_movement.getQuantity() * ratio
-> new status -> expanded edit_dict = dict(
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 )
An applied rule can be expanded only if its parent movement edit_dict['source'] = self.getSourcePayment()
is expanded. 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.
""" """
payment_line_type = 'Simulation Movement' payment_line_type = 'Simulation Movement'
my_parent_movement = applied_rule.getParentValue() my_parent_movement = applied_rule.getParentValue()
# generate for source
bank_account = self.getDestinationPaymentValue(
portal_type='Account')
assert bank_account is not None
if my_parent_movement.getQuantity() is not None: for payment_condition in self._getPaymentConditionList(
bank_id = 'bank' my_parent_movement):
if bank_id in applied_rule.objectIds(): payment_condition_url = payment_condition.getRelativeUrl()
bank_movement = applied_rule[bank_id] # 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:
bank_movement = applied_rule.newContent( # TODO: update corresponding_movement_list
portal_type=payment_line_type, pass
id = bank_id)
receivable_id = 'receivable' #Rule.expand(self, applied_rule, **kw)
if receivable_id in applied_rule.objectIds():
receivable_movement = applied_rule[receivable_id] def test(self, context, tested_base_category_list=None):
else: """Test if this rule apply.
receivable_movement = applied_rule.newContent( """
portal_type=payment_line_type, if context.getParentValue()\
id = receivable_id) .getSpecialiseValue().getPortalType() == 'Payment Rule':
return False
# TODO: specify this using a rule in portal_rules
# TODO: generate many movement according to different trade conditions for account in ( context.getSourceValue(portal_type='Account'),
bank_movement.edit( context.getDestinationValue(portal_type='Account')):
resource = my_parent_movement.getResource(), if account is not None:
quantity = my_parent_movement.getQuantity(), account_type = account.getAccountType()
source = 'account/banques_etablissements_financiers', # XXX Not Generic if account_type in self.receivable_account_type_list or \
destination = 'account/banques_etablissements_financiers', # XXX Not Generic account_type in self.payable_account_type_list:
source_section = my_parent_movement.getSourceSection(), return True
destination_section = my_parent_movement.getDestinationSection(),
) return False
receivable_movement.edit(
resource = my_parent_movement.getResource(),
quantity = - my_parent_movement.getQuantity(),
source = 'account/creance_client', # XXX Not Generic
destination = 'account/dette_fournisseur', # XXX Not Generic
source_section = my_parent_movement.getSourceSection(),
destination_section = my_parent_movement.getDestinationSection(),
)
Rule.expand(self, applied_rule, **kw)
def isDeliverable(self, m):
if m.getSimulationState() in self.getPortalDraftOrderStateList():
return 0
return 1
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