ProfitAndLoss.py 2.36 KB
Newer Older
Jean-Paul Smets's avatar
Jean-Paul Smets committed
1 2
##############################################################################
#
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
3
# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
4 5 6
#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
7
# programmers who take the whole responsibility of assessing all potential
Jean-Paul Smets's avatar
Jean-Paul Smets committed
8 9
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
10
# guarantees and support are strongly adviced to contract a Free Software
Jean-Paul Smets's avatar
Jean-Paul Smets committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# 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 CopyToTarget import CopyToTarget

class ProfitAndLoss(CopyToTarget):
  """
    Profit and Loss target rule.

    Many 'deliverable movements' are created in the Simulation and
    either source or destination is set to a ProfitAndLoss, depending
    on the parent applied rule.
  """

41
  def solve(self, simulation_movement):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
42 43 44 45
    """
      Movement difference as a profit (ie. a quantity coming from nowhere)
      Accumulate into delivered movement
    """
46
    delivery_line = simulation_movement.getDeliveryValue()
47 48
    delivery_line_quantity = delivery_line.getQuantity()
    if delivery_line_quantity is not None:
49 50 51
      target_quantity = delivery_line_quantity * simulation_movement.getDeliveryRatio()
      added_quantity = simulation_movement.getQuantity() - target_quantity
      simulation_movement.edit(profit_quantity=added_quantity)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
52 53
    delivery_line.activate(
      after_path_and_method_id=(
54
        simulation_movement.getPath(),
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
55 56 57
        ['immediateReindexObject', 'recursiveImmediateReindexObject']
      )
    ).edit()