Exemplo n.º 1
0
  def build(self, tag=None, input_movement_list=None,
                  existing_delivery_list=None, select_method_dict=None, 
                  explanation=None, business_link=None, **kwargs):
    """Builds document according to self configuration mixed with passed parameters

    Selecting parameters (like input movement list) might be passed directly
    to builder, but if not passed builder is able to find those values by
    itself.

    select_method_dict - dictionary which will be passed to input movement
      select method
    """
    # XXX: TODO backward compatibility with old parameters
    if select_method_dict is None:
      select_method_dict = {}
    # Call a script before building
    self.callBeforeBuildingScript()
    # Select movements
    if input_movement_list is None:
      if explanation is not None:
        explanation_cache = _getExplanationCache(explanation)
        path = explanation_cache.getSimulationPathPatternList()
      else:
        path = select_method_dict.get('path', None)
      if business_link is not None:
        causality_uid = business_link.getUid()
      else:
        causality_uid = select_method_dict.get('causality_uid', None)
      select_method_dict.update(dict(causality_uid=causality_uid, path=path))
      if select_method_dict.get('causality_uid') is None:
        business_link_value_list = self.getRelatedBusinessLinkValueList()
        if len(business_link_value_list) > 0:
          # use only Business Link related movements
          select_method_dict['causality_uid'] = [q.getUid() for q in business_link_value_list]
      # do search
      LOG('select_method_dict', 0, repr(select_method_dict))
      input_movement_value_list = self.searchMovementList(
        delivery_relative_url_list=existing_delivery_list, # XXX-JPS what is the purpose of existing_delivery_list
        **select_method_dict)
      LOG('input_movement_value_list', 0, repr(input_movement_value_list))
    else:
      # movements were passed directly either by url or by value
      if isinstance(input_movement_list[0], str):
        input_movement_value_list = [self.unrestrictedTraverse(relative_url) for
                                     relative_url in input_movement_list]
      else:
        input_movement_value_list = input_movement_list
        
    # Collect
    root_group_node = self.collectMovement(input_movement_value_list)
    # Build
    delivery_value_list = self.buildDeliveryList(
                       root_group_node,
                       delivery_relative_url_list=existing_delivery_list,
                       movement_list=input_movement_value_list)
    # Call a script after building
    self.callAfterBuildingScript(delivery_value_list,
        input_movement_value_list)
    return delivery_value_list
Exemplo n.º 2
0
    def build(self,
              applied_rule_uid=None,
              movement_relative_url_list=None,
              delivery_relative_url_list=None,
              movement_list=None,
              explanation=None,
              business_link=None,
              activate_kw=None,
              **kw):
        """
      Build deliveries from a list of movements

      Delivery Builders can also be provided with optional parameters to
      restrict selection to a given root Applied Rule caused by a single Order
      or to Simulation Movements related to a limited set of existing
    """
        # Parameter initialization
        if delivery_relative_url_list is None:
            delivery_relative_url_list = []
        # Call a script before building
        self.callBeforeBuildingScript()  # XXX-JPS Used ?
        # Select
        if not movement_list:
            if movement_relative_url_list:
                movement_list = map(self.restrictedTraverse,
                                    movement_relative_url_list)
            else:
                if explanation is not None:
                    explanation_cache = _getExplanationCache(explanation)
                    kw['path'] = explanation_cache.getSimulationPathPatternList(
                    )
                if business_link is not None:
                    kw['causality_uid'] = business_link.getUid()
                elif kw.get('causality_uid') is None:
                    business_link_value_list = self.getRelatedBusinessLinkValueList(
                    )
                    if len(business_link_value_list) > 0:
                        # use only Business Link related movements
                        kw['causality_uid'] = [
                            link_value.getUid()
                            for link_value in business_link_value_list
                        ]
                if applied_rule_uid is not None:
                    kw['applied_rule_uid'] = applied_rule_uid
                movement_list = self.searchMovementList(**kw)
                if not movement_list:
                    return []
        # Collect
        root_group_node = self.collectMovement(movement_list)
        # Build
        delivery_list = self.buildDeliveryList(
            root_group_node,
            delivery_relative_url_list=delivery_relative_url_list,
            movement_list=movement_list,
            activate_kw=activate_kw,
            **kw)
        # Call a script after building
        self.callAfterBuildingScript(delivery_list, movement_list, **kw)
        return delivery_list
Exemplo n.º 3
0
    def build(
        self,
        applied_rule_uid=None,
        movement_relative_url_list=None,
        delivery_relative_url_list=None,
        movement_list=None,
        explanation=None,
        business_link=None,
        activate_kw=None,
        **kw
    ):
        """
      Build deliveries from a list of movements

      Delivery Builders can also be provided with optional parameters to
      restrict selection to a given root Applied Rule caused by a single Order
      or to Simulation Movements related to a limited set of existing
    """
        # Parameter initialization
        if delivery_relative_url_list is None:
            delivery_relative_url_list = []
        # Call a script before building
        self.callBeforeBuildingScript()  # XXX-JPS Used ?
        # Select
        if not movement_list:
            if movement_relative_url_list:
                movement_list = map(self.restrictedTraverse, movement_relative_url_list)
            else:
                if explanation is not None:
                    explanation_cache = _getExplanationCache(explanation)
                    kw["path"] = explanation_cache.getSimulationPathPatternList()
                if business_link is not None:
                    kw["causality_uid"] = business_link.getUid()
                elif kw.get("causality_uid") is None:
                    business_link_value_list = self.getRelatedBusinessLinkValueList()
                    if len(business_link_value_list) > 0:
                        # use only Business Link related movements
                        kw["causality_uid"] = [link_value.getUid() for link_value in business_link_value_list]
                movement_list = self.searchMovementList(
                    delivery_relative_url_list=delivery_relative_url_list, applied_rule_uid=applied_rule_uid, **kw
                )
                if not movement_list:
                    return []
        # Collect
        root_group_node = self.collectMovement(movement_list)
        # Build
        delivery_list = self.buildDeliveryList(
            root_group_node,
            delivery_relative_url_list=delivery_relative_url_list,
            movement_list=movement_list,
            activate_kw=activate_kw,
            **kw
        )
        # Call a script after building
        self.callAfterBuildingScript(delivery_list, movement_list, **kw)
        return delivery_list
Exemplo n.º 4
0
    def getExpectedTradeModelPathStartAndStopDate(self,
                                                  explanation,
                                                  trade_model_path,
                                                  delay_mode=None):
        """Returns the expected start and stop dates of given Trade Model Path
    document in the context of provided explanation.

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

    trade_model_path -- a Trade Model Path document

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
    """
        if explanation.getParentValue().getPortalType() == 'Simulation Tool':
            raise ValueError('explanation must not be a Root Applied Rule')

        trade_date = trade_model_path.getTradeDate()
        assert trade_date, 'a trade_date must be defined on the Trade Model Path'

        reference_date_method_id = trade_model_path.getReferenceDateMethodId()
        if not reference_date_method_id:
            raise ValueError(
                'a reference date method must be defined on every Trade Model Path'
            )

        explanation_cache = _getExplanationCache(explanation)
        reference_date = explanation_cache.getReferenceDate(
            self, trade_date, reference_date_method_id)

        # Computer start_date and stop_date (XXX-JPS this could be cached and accelerated)
        start_date = reference_date + trade_model_path.getPaymentTerm(
            0.0)  # XXX-JPS Until better naming
        if delay_mode == 'min':
            delay = trade_model_path.getMinDelay(0.0)
        elif delay_mode == 'max':
            delay = trade_model_path.getMaxDelay(0.0)
        else:
            delay = (trade_model_path.getMaxDelay(0.0) +
                     trade_model_path.getMinDelay(0.0)) / 2.0
        stop_date = start_date + delay

        return start_date, stop_date
Exemplo n.º 5
0
  def getExpectedTradeModelPathStartAndStopDate(self, explanation, trade_model_path,
                                                      delay_mode=None):
    """Returns the expected start and stop dates of given Trade Model Path
    document in the context of provided explanation.

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

    trade_model_path -- a Trade Model Path document

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
    """
    if explanation.getParentValue().getPortalType() == 'Simulation Tool':
      raise ValueError('explanation must not be a Root Applied Rule')

    trade_date = trade_model_path.getTradeDate()
    assert trade_date, 'a trade_date must be defined on the Trade Model Path'

    reference_date_method_id = trade_model_path.getReferenceDateMethodId()
    if not reference_date_method_id:
      raise ValueError('a reference date method must be defined on every Trade Model Path')

    explanation_cache = _getExplanationCache(explanation)
    reference_date = explanation_cache.getReferenceDate(self, trade_date, reference_date_method_id)

    # Computer start_date and stop_date (XXX-JPS this could be cached and accelerated)    
    start_date = reference_date + trade_model_path.getPaymentTerm(0.0) # XXX-JPS Until better naming
    if delay_mode == 'min':
      delay = trade_model_path.getMinDelay(0.0)
    elif delay_mode == 'max':
      delay = trade_model_path.getMaxDelay(0.0)
    else:
      delay = (trade_model_path.getMaxDelay(0.0) + trade_model_path.getMinDelay(0.0)) / 2.0
    stop_date = start_date + delay
        
    return start_date, stop_date
 def _getExplanationRelatedMovementValueList(self, explanation):
     explanation_cache = _getExplanationCache(explanation)
     return explanation_cache.getTradeModelPathRelatedMovementValueList(
         self)
Exemplo n.º 7
0
 def _getExplanationRelatedMovementValueList(self, explanation):
   explanation_cache = _getExplanationCache(explanation)
   return explanation_cache.getTradeModelPathRelatedMovementValueList(self)
Exemplo n.º 8
0
 def _getExplanationRelatedMovementValueList(self, explanation):
   explanation_cache = _getExplanationCache(explanation)
   return explanation_cache.getBusinessLinkRelatedMovementValueList(self)