-
  In order to test the behaviour of the Procurement Auto Module
  we will create new rules for products and run the scheduler to
  see that results are good.
-
  We create a new frequency
-
  !record {model: stock.frequence, id: daily1}:
    name: daily
    daily_frequency_ok: True
    daily_frequency: 1
    start_date: !eval time.strftime('%Y-%m-%d', time.strptime('2010-03-03', '%Y-%m-%d'))
    no_end_date: True
-
  We create a new rule for product1
-
  !record {model: stock.warehouse.automatic.supply, id: r1}:
    category_id: product.cat0
    line_ids:
      - product_id: product1
        product_uom_id: product.product_uom_unit
        product_qty: 500
    warehouse_id: stock.warehouse0
    frequence_id: daily1
-
  We check if the compute next date is good
-
  !python {model: stock.warehouse.automatic.supply}: |
    from mx.DateTime import *
    next_date = self.browse(cr, uid, ref('r1')).next_date
    assert next_date == today().strftime('%Y-%m-%d'), "(1) Bad value for computed next date"
-
  We modify the frequence
-
  !record {model: stock.frequence, id: daily1}:
    name: yearly
    yearly_frequency: 1
    yearly_day_ok: 1
    yearly_day: 1
    yearly_choose_month: 1
-
  We check if the compute next date is equal to next January, the 1st
-
  !python {model: stock.warehouse.automatic.supply}: |
    from mx.DateTime import *
    today = today()
    next_date = self.browse(cr, uid, ref('r1')).next_date
    if today.day == 1 and today.month == 1:
      assert next_date == today.strftime('%Y-%m-%d'), "(2) Bad value for computed next date"
    else:
      good_date = DateTime(today.year+1, 1, 1)
      assert next_date == good_date.strftime('%Y-%m-%d'), "(3) Bad value for computed next date"
-
  We create a new frequency
-
  !record {model: stock.frequence, id: daily2}:
    name: daily
    daily_frequency_ok: True
    daily_frequency: 1
    start_date: !eval time.strftime('%Y-%m-%d', time.strptime('2010-03-03', '%Y-%m-%d'))
    no_end_date: True
-
  We create a new rule for product2
-
  !record {model: stock.warehouse.automatic.supply, id: r2}:
    category_id: product.cat0
    line_ids:
      - product_id: product2
        product_uom_id: product.product_uom_unit
        product_qty: 500
    warehouse_id: stock.warehouse0
    frequence_id: daily2
-
  We run the scheduler
-
  !python {model: procurement.order}: |
    self.run_automatic_supply(cr, uid, False, context={})
-
  Check if only one procurement has been created by the scheduler
-
  !python {model: procurement.order}: |
    p1_ids = self.search(cr, uid, [('product_id', '=', ref('product1'))])
    p2_ids = self.search(cr, uid, [('product_id', '=', ref('product2'))])
    assert len(p1_ids) == 0, "Error : the scheduler has created a procurement order for P1"
    assert len(p2_ids) == 1, "Error : the scheduler hasn't created a procurement order for P2"
