コード例 #1
0
 def _getCurrencyRatioAndPrecisionByArrow(self, arrow, prevision_line):
   prevision_currency = prevision_line.get('resource', None)
   exchange_ratio = None
   precision = None
   section = prevision_line.get(arrow, None)
   if section is not None:
     section = self.restrictedTraverse(section)
     currency_url = section.getProperty('price_currency', None)
   else:
     currency_url = None
   if currency_url is not None and prevision_currency != currency_url:
     from Products.ERP5Type.Document import newTempSimulationMovement
     temporary_movement = newTempSimulationMovement(self.getPortalObject(),
                                                    '1', **prevision_line)
     precision = section.getPriceCurrencyValue() \
         .getQuantityPrecision()
     exchange_ratio = self.restrictedTraverse(currency_url).getPrice(
         context=temporary_movement.asContext(
       categories=['price_currency/%s' % currency_url,
                   'resource/%s' % prevision_currency],
       start_date=temporary_movement.getStartDate()))
   return exchange_ratio, precision
コード例 #2
0
  sort_on=(('modification_date', 'ASC'),) # the highest chance to find movement which can be delivered
)
movement_list = portal.portal_catalog(**select_kw)

specialise = portal.portal_preferences.getPreferredAggregatedSaleTradeCondition()
temp_movement_list = []
id = 1
for movement in movement_list:
  if movement.getGroupingReference() is not None:
    continue
  temp_movement = newTempSimulationMovement(
    portal, movement.getRelativeUrl(),
    quantity=movement.getQuantity(),
    resource=movement.getResource(),
    source=movement.getDestination(),
    destination=movement.getDestination(),
    source_section=movement.getSourceSection(),
    destination_section=movement.getDestination(),
    destination_decision=movement.getDestination(),
    specialise=specialise,
    price_currency=movement.getPriceCurrency()
  )
  if movement.getResource() == 'service_module/slapos_instance_subscription':
    temp_movement.edit(price=0.83612040133800003)
  else:
    temp_movement.edit(price=0.0)
  temp_movement_list.append(temp_movement)
  id += 1

return temp_movement_list
コード例 #3
0
    def getTradePhaseMovementList(self,
                                  explanation,
                                  amount,
                                  trade_phase=None,
                                  delay_mode=None,
                                  update_property_dict=None):
        """Returns a list of movement with appropriate arrow and dates,
    based on the Business Link definitions, provided 'amount' and optional
    trade phases. If no trade_phase is provided, the trade_phase defined
    on the Amount is used instead.

    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree

    amount -- IAmount (quantity, resource) or IMovement

    trade_phase -- optional Trade Phase category

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay

    update_property_method --
    """
        if not trade_phase:
            trade_phase = amount.getTradePhaseList()
            if not trade_phase:
                raise ValueError("%s: a trade_phase must be defined on the " \
                                 "Amount or provided to getTradePhaseMovementList" %
                                  amount.getRelativeUrl())
        elif isinstance(trade_phase, basestring):
            trade_phase = trade_phase,

        # Build a list of temp movements
        from Products.ERP5Type.Document import newTempSimulationMovement
        result = []
        id_index = 0
        base_id = amount.getId()
        if update_property_dict is None: update_property_dict = {}
        filter_trade_phase = frozenset(trade_phase).intersection
        for trade_model_path in self.getTradeModelPathValueList(
                context=amount, trade_phase=trade_phase):
            id_index += 1
            movement = newTempSimulationMovement(trade_model_path,
                                                 '%s_%s' % (base_id, id_index),
                                                 notify_workflow=False)
            kw = self._getPropertyAndCategoryDict(explanation,
                                                  amount,
                                                  trade_model_path,
                                                  delay_mode=delay_mode)
            trade_phase = filter_trade_phase(
                trade_model_path.getTradePhaseList())
            try:
                kw['trade_phase'], = trade_phase
            except ValueError:
                pass
            kw.update(update_property_dict)
            movement._edit(force_update=True, **kw)
            business_link = self.getBusinessLinkValueList(
                trade_phase=trade_phase, context=movement)
            movement._setCausalityList(
                [trade_model_path.getRelativeUrl()] +
                [x.getRelativeUrl()
                 for x in business_link] + movement.getCausalityList())
            result.append(movement)

        if not explanation.getSpecialiseValue().getSameTotalQuantity():
            return result

        # result can not be empty
        if not result:
            raise ValueError(
                "A Business Process can not erase amounts:"
                " no Trade Model Path found for %r"
                " (rule=%s, trade_phase=%r)" %
                (amount, explanation.getSpecialise(), trade_phase))

        # Sort movement list and make sure the total is equal to total_quantity
        total_quantity = amount.getQuantity()
        current_quantity = 0
        result.sort(key=lambda x: x.getStartDate())
        stripped_result = []
        for movement in result:
            stripped_result.append(movement)
            quantity = movement.getQuantity()
            current_quantity += quantity
            if current_quantity > total_quantity:
                # As soon as the current_quantity is greater than total_quantity
                # strip the result
                break

        # Make sure total_quantity is reached by changing last movement valye
        if current_quantity != total_quantity:
            movement._setQuantity(quantity + total_quantity - current_quantity)

        return stripped_result
コード例 #4
0
ファイル: BusinessProcess.py プロジェクト: MarkTang/erp5
  def getTradePhaseMovementList(self, explanation, amount, trade_phase=None, delay_mode=None,
                                      update_property_dict=None):
    """Returns a list of movement with appropriate arrow and dates,
    based on the Business Link definitions, provided 'amount' and optional
    trade phases. If no trade_phase is provided, the trade_phase defined
    on the Amount is used instead.
    
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree

    amount -- IAmount (quantity, resource) or IMovement

    trade_phase -- optional Trade Phase category

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
                  
    update_property_method -- 
    """
    if not trade_phase:
      trade_phase = amount.getTradePhaseList()
      if not trade_phase:
        raise ValueError("%s: a trade_phase must be defined on the " \
                         "Amount or provided to getTradePhaseMovementList" %
                          amount.getRelativeUrl())
    elif isinstance(trade_phase, basestring):
      trade_phase = trade_phase,

    # Build a list of temp movements
    from Products.ERP5Type.Document import newTempSimulationMovement
    result = []
    id_index = 0
    base_id = amount.getId()
    if update_property_dict is None: update_property_dict = {}
    filter_trade_phase = frozenset(trade_phase).intersection
    for trade_model_path in self.getTradeModelPathValueList(context=amount, trade_phase=trade_phase):
      id_index += 1
      movement = newTempSimulationMovement(trade_model_path,
        '%s_%s' % (base_id, id_index), notify_workflow=False)
      kw = self._getPropertyAndCategoryDict(explanation, amount, trade_model_path, delay_mode=delay_mode)
      trade_phase = filter_trade_phase(trade_model_path.getTradePhaseList())
      try:
        kw['trade_phase'], = trade_phase
      except ValueError:
        pass
      kw.update(update_property_dict)
      movement._edit(force_update=True, **kw)
      business_link = self.getBusinessLinkValueList(trade_phase=trade_phase,
                                                    context=movement)
      movement._setCausalityList([trade_model_path.getRelativeUrl()]
        + [x.getRelativeUrl() for x in business_link]
        + movement.getCausalityList())
      result.append(movement)

    if not explanation.getSpecialiseValue().getSameTotalQuantity():
      return result

    # result can not be empty
    if not result:
      raise ValueError("A Business Process can not erase amounts:"
                       " no Trade Model Path found for %r"
                       " (rule=%s, trade_phase=%r)"
                       % (amount, explanation.getSpecialise(), trade_phase))

    # Sort movement list and make sure the total is equal to total_quantity
    total_quantity = amount.getQuantity()
    current_quantity = 0
    result.sort(key=lambda x:x.getStartDate())
    stripped_result = []
    for movement in result:
      stripped_result.append(movement)
      quantity = movement.getQuantity()
      current_quantity += quantity
      if current_quantity > total_quantity: 
        # As soon as the current_quantity is greater than total_quantity
        # strip the result
        break

    # Make sure total_quantity is reached by changing last movement valye
    if current_quantity != total_quantity:
      movement._setQuantity(quantity + total_quantity - current_quantity)

    return stripped_result
コード例 #5
0
  temp_movement_kw = dict(
    causality=invoice.getRelativeUrl(),
    source_section=invoice.getSourceSection(),
    destination_section=invoice.getDestinationSection(),
    resource=invoice.getResource(),
    price_currency=invoice.getResource(),
    start_date=invoice.getStartDate(),
    stop_date=invoice.getStopDate(),
    specialise=invoice.getSpecialise(),
    payment_mode=invoice.getPaymentMode(),
    source_payment='organisation_module/slapos/bank_account', # the other place defnied: business process
  )
  temp_movement_rec = newTempSimulationMovement(
    portal, str(id),
    quantity=-1 * quantity,
    source='account_module/receivable',
    destination='account_module/payable',
    **temp_movement_kw
  )
  id += 1
  temp_movement_bank = newTempSimulationMovement(
    portal, str(id),
    quantity=1 * quantity,
    source='account_module/bank',
    destination='account_module/bank',
    **temp_movement_kw
  )
  id += 1
  movement_list.extend([temp_movement_rec, temp_movement_bank])

return movement_list