def test_post_information_more_than_once_no_tic(self):
        """
      Check if posting information is working.
    """
        self.postInformation()
        self.commit()

        self.postInformation()
        self.tic()

        expectedFailure(self.assertEqual)(
            1,
            self.portal.portal_catalog.countResults(reference=self.key)[0][0])
        data_set = self.portal.portal_catalog.getResultValue(
            reference=self.key)
        self.assertEqual(self.key, data_set.getReference())
        self.assertEqual('published', data_set.getValidationState())

        document_list = data_set.getFollowUpRelatedValueList()

        self.assertEqual([self.sha512sum, self.sha512sum], [q.getReference() for q \
            in document_list])
        self.assertEqual(
            sorted(['published', 'archived']),
            sorted([q.getValidationState() for q in document_list]))
  def test_put_file_twice_no_tic(self):
    self.postFile()
    self.commit()
    self.postFile()
    self.tic()

    document_list = self.portal.portal_catalog(reference=self.key)

    self.assertEqual(2, len(document_list))
    expectedFailure(self.assertEqual)(sorted(['archived', 'published']),
        sorted(q.getValidationState() for q in document_list))
  def test_post_information_more_than_once_no_tic(self):
    """
      Check if posting information is working.
    """
    self.postInformation()
    self.commit()

    self.postInformation()
    self.tic()

    expectedFailure(self.assertEqual)(1,
      self.portal.portal_catalog.countResults(reference=self.key)[0][0])
    data_set = self.portal.portal_catalog.getResultValue(
      reference=self.key)
    self.assertEqual(self.key, data_set.getReference())
    self.assertEqual('published', data_set.getValidationState())

    document_list = data_set.getFollowUpRelatedValueList()

    self.assertEqual([self.sha512sum, self.sha512sum], [q.getReference() for q \
        in document_list])
    self.assertEqual(sorted(['published', 'archived']), sorted([
        q.getValidationState() for q in document_list]))
Exemple #4
0
  def catalog(self, reference_tree, kw, check_search_text=True,
      check_select_expression=True, expected_failure=False):
    reference_param_dict = self._catalog._queryResults(query_table='foo', **kw)
    query = self._catalog.buildQuery(kw)
    assertEqual = self.assertEqual
    if expected_failure:
      assertEqual = expectedFailure(assertEqual)

    assertEqual(reference_tree, query)
    search_text = query.asSearchTextExpression(self._catalog)
    if check_search_text:
      # XXX: sould "keyword" be always used for search text searches ?
      search_text_param_dict = self._catalog._queryResults(query_table='foo', keyword=search_text)
      if not check_select_expression:
        search_text_param_dict.pop('select_expression')
        reference_param_dict.pop('select_expression')
      assertEqual(reference_param_dict, search_text_param_dict,
          'Query: %r\nSearchText: %r\nReference: %r\nSecond rendering: %r' % \
                       (query, search_text, reference_param_dict, search_text_param_dict))
  def testQuantityUnitOnMovement(self):
    """Make sure that changing default quantity unit on resource does not
       affect to movement.
       In this test, always use Base.edit method. Because Base.edit is
       used when real user edit document through edit form.
    """
    # Set up quantity unit categories
    # weight
    quantity_unit_category_value = self.portal.portal_categories.quantity_unit
    quantity_unit_weight = quantity_unit_category_value._getOb('weight', None)
    if quantity_unit_weight is None:
      quantity_unit_weight = quantity_unit_category_value.newContent(
        id='weight', portal_type='Category')
    quantity_unit_gram = quantity_unit_weight._getOb('gram', None)
    if quantity_unit_gram is None:
      quantity_unit_gram = quantity_unit_weight.newContent(
        portal_type='Category', id='gram')
    # volume
    quantity_unit_volume = quantity_unit_category_value._getOb('volume', None)
    if quantity_unit_volume is None:
      quantity_unit_volume = quantity_unit_category_value.newContent(
        id='volume', portal_type='Category')
    quantity_unit_liter = quantity_unit_volume._getOb('liter', None)
    if quantity_unit_liter is None:
      quantity_unit_liter = quantity_unit_volume.newContent(
        portal_type='Category', id='liter')
    self.commit()

    # Create resource
    resource_value = self.portal.getDefaultModule(
      self.product_portal_type).newContent(portal_type=self.product_portal_type)
    resource_value.edit(quantity_unit_value_list=(
        quantity_unit_gram, quantity_unit_liter))
    self.commit()
    self.assertEqual(resource_value.getDefaultQuantityUnitValue(),
                     quantity_unit_gram)

    # Create sale order line
    sale_order = self.portal.getDefaultModule('Sale Order').newContent(
      portal_type='Sale Order')
    sale_order_line = sale_order.newContent(
      portal_type=self.sale_order_line_portal_type)
    self.commit()

    # Set resource to movement
    sale_order_line.edit(resource_value=resource_value)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_gram)

    # Select different quantity unit
    sale_order_line.edit(quantity_unit_value=quantity_unit_liter)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_liter)

    # Select empty(no quantity unit)
    sale_order_line.edit(quantity_unit_value=None)
    self.commit()

    # Select default quantity unit again
    sale_order_line.edit(quantity_unit_value=quantity_unit_gram)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_gram)

    # Change default quantity unit on resource
    # Now liter is default quantity unit.
    resource_value.edit(quantity_unit_value_list=(
        quantity_unit_liter, quantity_unit_gram))
    self.commit()

    # Check existing movement again and make sure that quantity
    # unit is not changed.
    expectedFailure(self.assertEqual)(
      sale_order_line.getQuantityUnitValue(),
      quantity_unit_gram)
Exemple #6
0
  def testOpenOrderRule(self):
    """
    Make sure that Open Order Rule can generate simulation movements by
    following trade conditon's periodicity setting and order's forecasting term.
    """
    open_sale_order = self.portal.open_sale_order_module.newContent(
      portal_type='Open Sale Order',
      specialise=self.portal.sale_trade_condition_module.trade_condition.getRelativeUrl(),
      start_date=DateTime(3000,2,9),
      stop_date=DateTime(3000,8,1),
      )

    open_sale_order_line = open_sale_order.newContent(
      portal_type='Open Sale Order Line',
      resource=self.portal.service_module.training.getRelativeUrl(),
      price=100,
      quantity=1)

    open_sale_order.Order_applyTradeCondition(open_sale_order.getSpecialiseValue())

    transaction.commit()
    self.tic()

    open_sale_order.setForecastingTermDayCount(5)
    open_sale_order.order()
    open_sale_order.start()

    transaction.commit()
    self.tic()

    applied_rule = open_sale_order.getCausalityRelatedValue(portal_type='Applied Rule')
    self.assertEqual(len(applied_rule.objectIds()), 0)

    open_order_rule = self.getRule(reference='default_open_order_rule')
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    transaction.commit()
    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 1)
    self.assertEqual(applied_rule['1'].getStartDate(), DateTime(3000,2,10,10,0))
    self.assertEqual(applied_rule['1'].getStopDate(), DateTime(3000,2,11,10,0))

    open_sale_order.setForecastingTermDayCount(10)
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    transaction.commit()
    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 2)
    self.assertEqual(applied_rule['2'].getStartDate(), DateTime(3000,2,17,10,0))
    self.assertEqual(applied_rule['2'].getStopDate(), DateTime(3000,2,18,10,0))

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    transaction.commit()
    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)
    # XXX: The following test is known to fail on machines that are configured
    #      to some specific timezones, due to a limitation of DateTime.
    expectedFailure(self.assertEqual)(
                     [(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0))
                      ])

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    transaction.commit()
    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)

    self.portal.sale_trade_condition_module.main_trade_condition.setExpirationDate(DateTime(3000,3,22))
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,30))

    transaction.commit()
    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 6)
    self.assertEqual([(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0)),
                      (DateTime(3000,3,17,10,0), DateTime(3000,3,18,10,0)),
                      ])
Exemple #7
0
class TestOpenOrder(ERP5TypeTestCase):
  """
  Test Open Order
  """

  def getTitle(self):
    return 'Test Open Order'

  def getBusinessTemplateList(self):

    return ('erp5_base',
            'erp5_pdm',
            'erp5_simulation',
            'erp5_trade',
            'erp5_open_trade',
            'erp5_open_trade_periodicity_line',
            'erp5_configurator_standard_trade_template',
            'erp5_simulation_test')

  def afterSetUp(self):
    if getattr(self.portal, '_run_after_setup', None) is not None:
      return

    #self.getRule(reference='default_open_order_rule').validate()
    self.getRule(reference='default_order_rule').validate()

    self.portal.portal_categories.base_amount.newContent(
      id='taxable',
      portal_type='Category',
      title='Taxable')
    tax = self.portal.service_module.newContent(
      portal_type='Service',
      title='VAT',
      base_contribution='base_amount/taxable')
    client = self.portal.organisation_module.newContent(
      id='client',
      portal_type='Organisation',
      title='Client')
    vendor = self.portal.organisation_module.newContent(
      id='vendor',
      portal_type='Organisation',
      title='Vendor')
    internet_connection = self.portal.service_module.newContent(
      id='internet_connection',
      title='Internet Connection',
      base_contribution='base_amount/taxable')
    training = self.portal.service_module.newContent(
      id='training',
      title='Training',
      base_contribution='base_amount/taxable')
    bread = self.portal.product_module.newContent(
      id='bread',
      title='Bread',
      base_contribution='base_amount/taxable')
    water = self.portal.product_module.newContent(
      id='water',
      title='Water',
      base_contribution='base_amount/taxable')
    main_trade_condition = self.portal.sale_trade_condition_module.newContent(
      id='main_trade_condition',
      portal_type='Sale Trade Condition',
      title='Vendor ---> Client',
      source=vendor.getRelativeUrl(),
      source_section=vendor.getRelativeUrl(),
      destination=client.getRelativeUrl(),
      destination_section=client.getRelativeUrl(),
      )
    main_trade_condition.newContent(portal_type='Trade Model Line',
                               title='VAT',
                               base_application='base_amount/taxable',
                               price=0.05)
    main_trade_condition.newContent(portal_type='Sale Supply Line',
                               resource=internet_connection.getRelativeUrl(),
                               priced_quantity=1,
                               base_price=200)
    # Use periodicity_minute=1 in order to see more details of DateTime
    # instance. Because if the time is 00:00:00, then it omits to display
    # some information like timezone for example.
    main_trade_condition.newContent(
      id='internet_connection_periodicity_line',
      portal_type='Periodicity Line',
      resource=internet_connection.getRelativeUrl(),
      periodicity_term_scope_type='until_the_end_of_month',
      periodicity_minute=1,
      periodicity_hour=0,
      periodicity_month_day=1)
    main_trade_condition.newContent(portal_type='Sale Supply Line',
                                    resource=training.getRelativeUrl(),
                                    priced_quantity=4,
                                    base_price=400)
    main_trade_condition.newContent(
      id='training_periodicity_line',
      portal_type='Periodicity Line',
      resource=training.getRelativeUrl(),
      periodicity_term_time_scale='day',
      periodicity_term_length_number=1,
      periodicity_hour=10,
      periodicity_week_day='Monday')
    main_trade_condition.newContent(portal_type='Sale Supply Line',
                               resource=bread.getRelativeUrl(),
                               priced_quantity=1,
                               base_price=10)
    main_trade_condition.newContent(
      id='bread_periodicity_line',
      portal_type='Periodicity Line',
      resource=bread.getRelativeUrl(),
      periodicity_term_time_scale='day',
      periodicity_term_length_number=0,
      periodicity_minute=0,
      periodicity_hour_list=(6, 12),
      periodicity_week_day_list=('Monday',
                                 'Tuesday',
                                 'Wednesday',
                                 'Thursday',
                                 'Friday',
                                 'Saturday'))
    main_trade_condition.newContent(portal_type='Sale Supply Line',
                               resource=water.getRelativeUrl(),
                               priced_quantity=1,
                               base_price=5)
    main_trade_condition.newContent(
      id='water_periodicity_line',
      portal_type='Periodicity Line',
      resource=water.getRelativeUrl(),
      periodicity_term_scope_type='until_the_next_period',
      periodicity_minute=0,
      periodicity_hour_list=10,
      periodicity_week_frequency=2,
      periodicity_week_day = 'Monday')

    # Inherit trade conditions to make sure that it works.
    useless_trade_condition = self.portal.sale_trade_condition_module.newContent(
      portal_type='Sale Trade Condition')

    self.portal.sale_trade_condition_module.newContent(
      id='trade_condition',
      portal_type='Sale Trade Condition',
      specialise_list=(useless_trade_condition.getRelativeUrl(),
                       main_trade_condition.getRelativeUrl())
      )
     
    self.portal._run_after_setup = True
    self.tic()

  def _testPeriodicityDateList(self, timezone=None):
    """
    Make sure that periodicity line can generate correct schedule.
    """
    #self.fail('Test disabled because it freezes')
    def D(yr, mo, dy, hr=0, mn=0, sc=0):
      return DateTime(yr, mo, dy, hr, mn, sc, timezone)
    # This across Summer time period, if server's timezone uses it.
    # XXX: The following test is known to fail on machines that are configured
    #      to some specific timezones, due to a limitation of DateTime.
    self.assertEqual(self.portal.sale_trade_condition_module.main_trade_condition.internet_connection_periodicity_line.getDatePeriodList(
      D(2008,1,15), D(2008,12,1)),
                    [(D(2008,2,1,0,1), DateTime(2008,2,29)),
                      (D(2008,3,1,0,1), DateTime(2008,3,31)),
                      (D(2008,4,1,0,1), DateTime(2008,4,30)),
                      (D(2008,5,1,0,1), DateTime(2008,5,31)),
                      (D(2008,6,1,0,1), DateTime(2008,6,30)),
                      (D(2008,7,1,0,1), DateTime(2008,7,31)),
                      (D(2008,8,1,0,1), DateTime(2008,8,31)),
                      (D(2008,9,1,0,1), DateTime(2008,9,30)),
                      (D(2008,10,1,0,1), DateTime(2008,10,31)),
                      (D(2008,11,1,0,1), DateTime(2008,11,30)),
                      ])

    self.assertEqual(self.portal.sale_trade_condition_module.main_trade_condition.bread_periodicity_line.getDatePeriodList(
      D(2008,2,26), D(2008,3,5)),
                    [(D(2008,2,26,6,0), D(2008,2,26,6,0)),
                      (D(2008,2,26,12,0), D(2008,2,26,12,0)),
                      (D(2008,2,27,6,0), D(2008,2,27,6,0)),
                      (D(2008,2,27,12,0), D(2008,2,27,12,0)),
                      (D(2008,2,28,6,0), D(2008,2,28,6,0)),
                      (D(2008,2,28,12,0), D(2008,2,28,12,0)),
                      (D(2008,2,29,6,0), D(2008,2,29,6,0)),
                      (D(2008,2,29,12,0), D(2008,2,29,12,0)),
                      (D(2008,3,1,6,0), D(2008,3,1,6,0)),
                      (D(2008,3,1,12,0), D(2008,3,1,12,0)),
                      (D(2008,3,3,6,0), D(2008,3,3,6,0)),
                      (D(2008,3,3,12,0), D(2008,3,3,12,0)),
                      (D(2008,3,4,6,0), D(2008,3,4,6,0)),
                      (D(2008,3,4,12,0), D(2008,3,4,12,0)),
                      ])

    self.assertEqual(self.portal.sale_trade_condition_module.main_trade_condition.water_periodicity_line.getDatePeriodList(
      D(2008,2,16), D(2008,4,15)),
                    [(D(2008,2,18,10,0), D(2008,3,3,10,0)),
                      (D(2008,3,3,10,0), D(2008,3,17,10,0)),
                      (D(2008,3,17,10,0), D(2008,3,31,10,0)),
                      (D(2008,3,31,10,0), D(2008,4,14,10,0)),
                      (D(2008,4,14,10,0), D(2008,4,28,10,0)),
                      ])
    self.assertEqual(self.portal.sale_trade_condition_module.main_trade_condition.training_periodicity_line.getDatePeriodList(
      D(2008,2,16), D(2008,3,6)),
                    [(D(2008,2,18,10,0), D(2008,2,19,10,0)),
                      (D(2008,2,25,10,0), D(2008,2,26,10,0)),
                      (D(2008,3,3,10,0), D(2008,3,4,10,0)),
                      ])

  testPeriodicityDateList = expectedFailure(_testPeriodicityDateList)

  def testPeriodicityDateListUniversal(self):
    self._testPeriodicityDateList('Universal')

  @expectedFailure
  def testOpenOrderRule(self):
    """
    Make sure that Open Order Rule can generate simulation movements by
    following trade conditon's periodicity setting and order's forecasting term.
    """
    open_sale_order = self.portal.open_sale_order_module.newContent(
      portal_type='Open Sale Order',
      specialise=self.portal.sale_trade_condition_module.trade_condition.getRelativeUrl(),
      start_date=DateTime(3000,2,9),
      stop_date=DateTime(3000,8,1),
      )

    open_sale_order_line = open_sale_order.newContent(
      portal_type='Open Sale Order Line',
      resource=self.portal.service_module.training.getRelativeUrl(),
      price=100,
      quantity=1)

    open_sale_order.Order_applyTradeCondition(open_sale_order.getSpecialiseValue())

    self.tic()

    open_sale_order.setForecastingTermDayCount(5)
    open_sale_order.order()
    open_sale_order.start()

    self.tic()

    applied_rule = open_sale_order.getCausalityRelatedValue(portal_type='Applied Rule')
    self.assertEqual(len(applied_rule.objectIds()), 0)

    open_order_rule = self.getRule(reference='default_open_order_rule')
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 1)
    self.assertEqual(applied_rule['1'].getStartDate(), DateTime(3000,2,10,10,0))
    self.assertEqual(applied_rule['1'].getStopDate(), DateTime(3000,2,11,10,0))

    open_sale_order.setForecastingTermDayCount(10)
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 2)
    self.assertEqual(applied_rule['2'].getStartDate(), DateTime(3000,2,17,10,0))
    self.assertEqual(applied_rule['2'].getStopDate(), DateTime(3000,2,18,10,0))

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)
    # XXX: The following test is known to fail on machines that are configured
    #      to some specific timezones, due to a limitation of DateTime.
    expectedFailure(self.assertEqual)(
                     [(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0))
                      ])

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)

    self.portal.sale_trade_condition_module.main_trade_condition.setExpirationDate(DateTime(3000,3,22))
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,30))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 6)
    self.assertEqual([(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0)),
                      (DateTime(3000,3,17,10,0), DateTime(3000,3,18,10,0)),
                      ])

  @expectedFailure
  def testBuildingSaleOrder(self):
    """
    Make sure that open sale order can create sale orders repeatedly
    """
    open_sale_order = self.portal.open_sale_order_module.newContent(
      portal_type='Open Sale Order',
      specialise=self.portal.sale_trade_condition_module.trade_condition.getRelativeUrl(),
      start_date=DateTime(3000,2,9),
      stop_date=DateTime(3000,8,1),
      forecasting_term_day_count=5
      )

    # Remove other test's side effect.
    self.portal.sale_trade_condition_module.main_trade_condition.setExpirationDate(None)

    self.tic()

    open_sale_order.newContent(
      title='Piano Lesson',
      portal_type='Open Sale Order Line',
      resource=self.portal.service_module.training.getRelativeUrl(),
      quantity=1)

    open_sale_order.newContent(
      title='Internet Connection',
      portal_type='Open Sale Order Line',
      resource=self.portal.service_module.internet_connection.getRelativeUrl(),
      quantity=1)

    open_sale_order.newContent(
      title='Bread Delivery Serivce',
      portal_type='Open Sale Order Line',
      resource=self.portal.product_module.bread.getRelativeUrl(),
      quantity=1)

    open_sale_order.newContent(
      title='Mineral Water Delivery Service',
      portal_type='Open Sale Order Line',
      resource=self.portal.product_module.water.getRelativeUrl(),
      quantity=1)

    open_sale_order.Order_applyTradeCondition(open_sale_order.getSpecialiseValue())

    self.tic()

    open_sale_order.order()
    open_sale_order.start()

    self.tic()

    applied_rule = open_sale_order.getCausalityRelatedValue(portal_type='Applied Rule')
    self.assertEqual(len(applied_rule.objectIds()), 0)

    open_sale_order.autoOrderPeriodically(comment='Test', calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 9)
    self.assertEqual(len(open_sale_order.getCausalityRelatedValueList(portal_type='Sale Order')), 9)

    # Do the same thing and nothing happens.
    open_sale_order.autoOrderPeriodically(comment='Test', calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 9)
    self.assertEqual(len(open_sale_order.getCausalityRelatedValueList(portal_type='Sale Order')), 9)

    # Next
    open_sale_order.autoOrderPeriodically(comment='Test', calculation_base_date=DateTime(3000,2,14))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 19)
    self.assertEqual(len(open_sale_order.getCausalityRelatedValueList(portal_type='Sale Order')), 19)

    # Check sale orders
    sale_order_list = [
      brain.getObject()
      for brain in self.portal.portal_catalog(portal_type='Sale Order',
                                              causality_uid=open_sale_order.getUid(),
                                              sort_on='delivery.start_date')]

    # The first order is bread.
    self.assertEqual(
      len(sale_order_list[0].objectValues(portal_type='Sale Order Line')),
      1)
    self.assertEqual(
      sale_order_list[0].objectValues(portal_type='Sale Order Line')[0].getTitle(),
      'Bread Delivery Serivce')
    self.assertEqual(sale_order_list[0].getTotalPrice(), 10)
    # TODO: test equivalent feature with trade model line
    # self.assertEqual(sale_order_list[0].getTotalNetPrice(), 10.5)

    # The second order is piano lesson.
    self.assertEqual(
      len(sale_order_list[1].objectValues(portal_type='Sale Order Line')),
      1)
    self.assertEqual(
      sale_order_list[1].objectValues(portal_type='Sale Order Line')[0].getTitle(),
      'Piano Lesson')
    self.assertEqual(sale_order_list[1].getTotalPrice(), 100)
Exemple #8
0
  def testOpenOrderRule(self):
    """
    Make sure that Open Order Rule can generate simulation movements by
    following trade conditon's periodicity setting and order's forecasting term.
    """
    open_sale_order = self.portal.open_sale_order_module.newContent(
      portal_type='Open Sale Order',
      specialise=self.portal.sale_trade_condition_module.trade_condition.getRelativeUrl(),
      start_date=DateTime(3000,2,9),
      stop_date=DateTime(3000,8,1),
      )

    open_sale_order_line = open_sale_order.newContent(
      portal_type='Open Sale Order Line',
      resource=self.portal.service_module.training.getRelativeUrl(),
      price=100,
      quantity=1)

    open_sale_order.Order_applyTradeCondition(open_sale_order.getSpecialiseValue())

    self.tic()

    open_sale_order.setForecastingTermDayCount(5)
    open_sale_order.order()
    open_sale_order.start()

    self.tic()

    applied_rule = open_sale_order.getCausalityRelatedValue(portal_type='Applied Rule')
    self.assertEqual(len(applied_rule.objectIds()), 0)

    open_order_rule = self.getRule(reference='default_open_order_rule')
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 1)
    self.assertEqual(applied_rule['1'].getStartDate(), DateTime(3000,2,10,10,0))
    self.assertEqual(applied_rule['1'].getStopDate(), DateTime(3000,2,11,10,0))

    open_sale_order.setForecastingTermDayCount(10)
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,2,9))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 2)
    self.assertEqual(applied_rule['2'].getStartDate(), DateTime(3000,2,17,10,0))
    self.assertEqual(applied_rule['2'].getStopDate(), DateTime(3000,2,18,10,0))

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)
    # XXX: The following test is known to fail on machines that are configured
    #      to some specific timezones, due to a limitation of DateTime.
    expectedFailure(self.assertEqual)(
                     [(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0))
                      ])

    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,1))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 5)

    self.portal.sale_trade_condition_module.main_trade_condition.setExpirationDate(DateTime(3000,3,22))
    open_order_rule.expand(
      applied_rule,
      calculation_base_date=DateTime(3000,3,30))

    self.tic()

    self.assertEqual(len(applied_rule.objectIds()), 6)
    self.assertEqual([(movement.getStartDate(), movement.getStopDate())
                      for movement in applied_rule.objectValues(sort_on='start_date')],
                     [(DateTime(3000,2,10,10,0), DateTime(3000,2,11,10,0)),
                      (DateTime(3000,2,17,10,0), DateTime(3000,2,18,10,0)),
                      (DateTime(3000,2,24,10,0), DateTime(3000,2,25,10,0)),
                      (DateTime(3000,3,3,10,0), DateTime(3000,3,4,10,0)),
                      (DateTime(3000,3,10,10,0), DateTime(3000,3,11,10,0)),
                      (DateTime(3000,3,17,10,0), DateTime(3000,3,18,10,0)),
                      ])
Exemple #9
0
]:
    implements_tuple_list.append(
        (("Products.ERP5Type.Document.%s" % movement_group_class_name, movement_group_class_name), "IMovementGroup")
    )


class TestERP5Interfaces(ERP5TypeTestCase):
    """Tests implementation of interfaces"""


addTestMethodDynamically(TestERP5Interfaces, implements_tuple_list)

for failing_method in [
    "test_Products.ERP5.AggregatedAmountList_AggregatedAmountList_implements_IAmountList",
    "test_Products.ERP5.Document.BusinessLink_BusinessLink_implements_IBusinessLink",
    "test_Products.ERP5.Document.BusinessLink_BusinessLink_implements_ICategoryAccessProvider",
    "test_Products.ERP5.Document.TradeModelCell_TradeModelCell_implements_IVariated",
    "test_Products.ERP5.Document.TradeModelLine_TradeModelLine_implements_IVariated",
    "test_Products.ERP5Legacy.Document.TradeModelRule_TradeModelRule_implements_IRule",
    "test_Products.ERP5Legacy.Document.TransformationRule_TransformationRule_implements_IRule",
    "test_Products.ERP5.Document.Transformation_Transformation_implements_IVariated",
    "test_Products.ERP5.Document.TransformedResource_TransformedResource_implements_IVariated",
]:
    setattr(TestERP5Interfaces, failing_method, expectedFailure(getattr(TestERP5Interfaces, failing_method)))


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestERP5Interfaces))
    return suite
Exemple #10
0

def addTestMethodDynamically(test_class, implements_tuple_list):
    """Creates test methods on the fly

    Uses naming
    test_<ImportPathOfClass>_<ImplementationClass>_implements_<InterfaceClass>

    It is possible to use --run_only on those dynamically generated methods"""
    for import_tuple, interface in implements_tuple_list:
        method_name = '_'.join(('test', ) + import_tuple + ('implements', ) +
                               (interface, ))
        method = makeTestMethod(import_tuple, interface)
        setattr(test_class, method_name, method)


# Note: Enable this method when implements_tuple_list will be filled
addTestMethodDynamically(TestERP5TypeInterfaces, implements_tuple_list)

for failing_method in [
        'test_Products.ERP5Type.ConsistencyMessage_ConsistencyMessage_implements_IConsistencyMessage',
]:
    setattr(TestERP5TypeInterfaces, failing_method,
            expectedFailure(getattr(TestERP5TypeInterfaces, failing_method)))


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestERP5TypeInterfaces))
    return suite
Exemple #11
0
  def testQuantityUnitOnMovement(self):
    """Make sure that changing default quantity unit on resource does not
       affect to movement.
       In this test, always use Base.edit method. Because Base.edit is
       used when real user edit document through edit form.
    """
    # Set up quantity unit categories
    # weight
    quantity_unit_category_value = self.portal.portal_categories.quantity_unit
    quantity_unit_weight = quantity_unit_category_value._getOb('weight', None)
    if quantity_unit_weight is None:
      quantity_unit_weight = quantity_unit_category_value.newContent(
        id='weight', portal_type='Category')
    quantity_unit_gram = quantity_unit_weight._getOb('gram', None)
    if quantity_unit_gram is None:
      quantity_unit_gram = quantity_unit_weight.newContent(
        portal_type='Category', id='gram')
    # volume
    quantity_unit_volume = quantity_unit_category_value._getOb('volume', None)
    if quantity_unit_volume is None:
      quantity_unit_volume = quantity_unit_category_value.newContent(
        id='volume', portal_type='Category')
    quantity_unit_liter = quantity_unit_volume._getOb('liter', None)
    if quantity_unit_liter is None:
      quantity_unit_liter = quantity_unit_volume.newContent(
        portal_type='Category', id='liter')
    self.commit()

    # Create resource
    resource_value = self.portal.getDefaultModule(
      self.product_portal_type).newContent(portal_type=self.product_portal_type)
    resource_value.edit(quantity_unit_value_list=(
        quantity_unit_gram, quantity_unit_liter))
    self.commit()
    self.assertEqual(resource_value.getDefaultQuantityUnitValue(),
                     quantity_unit_gram)

    # Create sale order line
    sale_order = self.portal.getDefaultModule('Sale Order').newContent(
      portal_type='Sale Order')
    sale_order_line = sale_order.newContent(
      portal_type=self.sale_order_line_portal_type)
    self.commit()

    # Set resource to movement
    sale_order_line.edit(resource_value=resource_value)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_gram)

    # Select different quantity unit
    sale_order_line.edit(quantity_unit_value=quantity_unit_liter)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_liter)

    # Select empty(no quantity unit)
    sale_order_line.edit(quantity_unit_value=None)
    self.commit()

    # Select default quantity unit again
    sale_order_line.edit(quantity_unit_value=quantity_unit_gram)
    self.commit()
    self.assertEqual(sale_order_line.getQuantityUnitValue(),
                     quantity_unit_gram)

    # Change default quantity unit on resource
    # Now liter is default quantity unit.
    resource_value.edit(quantity_unit_value_list=(
        quantity_unit_liter, quantity_unit_gram))
    self.commit()

    # Check existing movement again and make sure that quantity
    # unit is not changed.
    expectedFailure(self.assertEqual)(
      sale_order_line.getQuantityUnitValue(),
      quantity_unit_gram)