-
  In order to test features of the stock_schedule module,
  I will create a new planification with yearly parameter and test
  different cases
-
  First yearly test
-
  !record {model: stock.frequence, id: yearly1}:
    name: yearly
    yearly_frequency: 2
    yearly_day_ok: 1
    yearly_day: 3
    yearly_choose_month: 3
    start_date: !eval time.strftime('%Y-03-03')
    last_run: !eval time.strftime('%Y-03-03')
    no_end_date: True
-
  Check if the next date is the next March, the 3rd of an odd-numbered year
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly1')).next_date)
    next_yearly = today() + RelativeDate(years=+2,day=3, month=3)
    assert next_date == next_yearly, "Next date is not March, the 3rd of year+2"
-
  Change the start date to today
-
  !record {model: stock.frequence, id: yearly1}:
    start_date: 2009-01-01
    last_run: !eval time.strftime('%Y-%m-%d')
    yearly_day: !eval time.localtime()[2]
    yearly_choose_month: !eval time.localtime()[1]
-
  Check if the next date is always March, the 3rd of an odd-numbered year
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly1')).next_date)
    if today().month == 2 and today().day == 29:
      assert next_date.month == 3 and next_date.day == 1, 'Next date is not March, the 1st (2) %s' % next_date
    else:
      assert next_date.month == today().month and next_date.day == today().day, 'Next date is not correct (2) %s' % next_date
-
  Change the choose month to October
-
  !record {model: stock.frequence, id: yearly1}:
    yearly_choose_month: 10
    yearly_day: 3
-
  Check if the next date is now the next October, the 3rd
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly1')).next_date)
    assert next_date == DateTime(today().year+2, 10, 3) and next_date >= today(), "Next date is not October, the 3rd of %s"%(today().year+2,)
-
  Second yearly test
-
  !record {model: stock.frequence, id: yearly2}:
    name: yearly
    yearly_frequency: 2
    yearly_date_ok: 1
    yearly_day_ok: 0
    yearly_choose_freq: 1
    yearly_choose_day: wednesday
    yearly_choose_month_freq: 3
    start_date: '2009-03-03'
    last_run: '2009-03-03'
    no_end_date: True
-
  Check if the next date is the first wednesday of March
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly2')).next_date)
    last = strptime('2009-03-03','%Y-%m-%d')
    last += RelativeDate(years=2)

    next = last + RelativeDate(weekday=(Wednesday,1))

    if next > today():
        assert next == next_date, "The next date is not the first Wednesday of March (1)"
    else:
        assert today() == next_date, "The next date is not the first Wednesday of March (2)"
-
  First yearly test
-
  !record {model: stock.frequence, id: yearly3}:
    name: yearly
    yearly_frequency: 2
    yearly_day_ok: 1
    yearly_day: 3
    yearly_choose_month: 3
    start_date: !eval time.strftime('%Y-03-03')
    last_run: !eval time.strftime('%Y-03-03')
    no_end_date: True
-
  Check if the next date is the next March, the 3rd of an odd-numbered year
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly3')).next_date)
    next_yearly = today() + RelativeDate(years=+2,day=3, month=3)
    assert next_date == next_yearly, "Next date is not March, the 3rd of year+2"
-
  Change the start date to October the 3rd.
-
  !record {model: stock.frequence, id: yearly3}:
    start_date: 2009-01-01
    last_run: !eval time.strftime('2009-%m-28')
    yearly_day: !eval time.localtime()[2]
    yearly_choose_month: !eval time.localtime()[1]
-
  Check if the next date is always March, the 3rd of an odd-numbered year
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly3')).next_date)
    last_run = Parser.DateFromString(self.browse(cr, uid, ref('yearly3')).last_run)
    if (now() - last_run).days > 730:
      assert (next_date.year-today().year) == 0, 'Next date is not today'
    else:
      assert (next_date.year-2009)%2 == 0, 'Next date is not multiple of 2'
    assert next_date.month == today().month and next_date.day == today().day, 'Next date is not March, the 3rd (2)'
-
  Change the choose month to October
-
  !record {model: stock.frequence, id: yearly3}:
    yearly_choose_month: 10
    yearly_day: 3
-
  Check if the next date is now the next October, the 3rd
-
  !python {model: stock.frequence}: |
    from mx.DateTime import *
    next_date = Parser.DateFromString(self.browse(cr, uid, ref('yearly3')).next_date)
    last_run = Parser.DateFromString(self.browse(cr, uid, ref('yearly3')).last_run)
    next_yearly = DateTime(2009, 10, 03)
    if (now() - last_run).days > 730:
      assert next_date == DateTime(now().year, now().month, now().day), "Next date is not today"
    else:
      if (today().year-2009)%2 == 0:
        if today().month < 10 or (today().month == 10 and today().day <= 3):
          assert next_date == DateTime(today().year, 10, 3) and next_date >= today(), "Next date is not October, the 3rd of the current year"
        else:
          assert next_date == DateTime(today().year+2, 10, 3) and next_date >= today(), "Next date is not October, the 3rd of %s"%(today().year+2,)
      else:
        assert next_date == DateTime(today().year+1, 10, 3) and next_date >= today(), "Next date is not October, the 3rd of %s"%(today().year+1,)