PaymentRule.py 3.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
#                    Sebastien Robin <seb@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

from AccessControl import ClassSecurityInfo
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
from Products.CMFCore.utils import getToolByName

33
from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
34 35
from Products.ERP5.Document.Rule import Rule

36
from zLOG import LOG, INFO
37 38

class PaymentRule(Rule):
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
39 40 41 42 43 44 45 46 47 48 49 50
  """Payment Rule generates payment simulation movement from invoice
  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)
51

Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
52 53 54
  receivable_account_type_list = ('asset/receivable', )
  payable_account_type_list = ('liability/payable', )

55
  def _generatePrevisionList(self, applied_rule, **kw):
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
56
    """
57 58 59
    Generate a list of dictionaries, that contain calculated content of
    current Simulation Movements in applied rule.
    based on its context (parent movement, delivery, configuration ...)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
60

61
    These previsions are returned as dictionaries.
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
62
    """
63 64 65 66 67 68 69 70 71 72
    prevision_dict_list = []
    for input_movement, business_path in self \
        ._getInputMovementAndPathTupleList(applied_rule):
      if business_path is None:
        # since Payment Rule does not know what to do without business
        # path, we return empty list here and creates no simulation
        # movements.
        return []
      # Since we need to consider business_path only for bank movement,
      # not for payable movement, we pass None as business_path here.
73
      kw = self._getExpandablePropertyDict(applied_rule, input_movement, None)
74 75 76 77 78 79
      kw['start_date'] = business_path.getExpectedStartDate(input_movement)
      kw['stop_date'] = business_path.getExpectedStopDate(input_movement)
      quantity = business_path.getExpectedQuantity(input_movement)

      # one for payable
      payable_dict = kw.copy()
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
80
      payable_dict.update(dict(quantity=-quantity))
81 82 83
      prevision_dict_list.append(payable_dict)
      # one for bank
      bank_dict = kw.copy()
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
84
      bank_dict.update(dict(quantity=quantity,
85 86 87 88
                            source=business_path.getSource(),
                            destination=business_path.getDestination()))
      prevision_dict_list.append(bank_dict)
    return prevision_dict_list
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
89 90 91 92 93

  security.declareProtected(Permissions.ModifyPortalContent, 'expand')
  def expand(self, applied_rule, **kw):
    """Expands the current movement downward.
    """
94
    return Rule._expand(self, applied_rule, **kw)