-
  In order to test dates in Orders, I create initial data
-
    I create 4 partners
-
    I create a customer C1
-
  !record {model: res.partner, id: cust1}:
    name: C1
    customer: True
-
    I create an address for C1
-
  !record {model: res.partner.address, id: addrc1}:
    name: C1
    partner_id: cust1 
-
    I create supplier S1
-
  !record {model: res.partner, id: supplier1}:
    name: S1
    supplier: True
-
    I create the address for S1
-
  !record {model: res.partner.address, id: address1}:
    name: S1
    partner_id: supplier1
-
    I create the supplier S2
-
  !record {model: res.partner, id: supplier2}:
    name: S2
    supplier: True
-
    I create the address for S2
-
  !record {model: res.partner.address, id: address2}:
    name: S2
    partner_id: supplier2
-
    I create the supplier S3
-
  !record {model: res.partner, id: supplier3}:
    name: S3
    supplier: True
-
    I create the address for S3
-
  !record {model: res.partner.address, id: address3}:
    name: S3
    partner_id: supplier3
-
    In order to test the procurement list module, I start by creating a new product category
-
  !record {model: product.category, id: product_cat1}:
    name: Categ1
-
    And a second category
-
  !record {model: product.category, id: product_cat2}:
    name: Categ2
-
    I create the product P1
-
  !record {model: product.product, id: product1}:
    categ_id: product_cat1
    cost_method: standard
    mes_type: fixed
    name: P1
    price_margin: 2.0
    procure_method: make_to_stock
    property_stock_inventory: stock.location_inventory
    property_stock_procurement: stock.location_procurement
    property_stock_production: stock.location_production
    seller_delay: '1'
    standard_price: 100.0
    supply_method: buy
    type: product
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
    volume : 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
    reviewed_consumption: 45
    seller_ids:
      - sequence: 10
        min_qty: 0.00
        name: supplier1
        delay: 12
      - sequence: 20
        min_qty: 0.00
        name: supplier2
        delay: 45
-
    I create a second product, P2
-
  !record {model: product.product, id: product2}:
    categ_id: product_cat1
    cost_method: standard
    mes_type: fixed
    name: P2
    price_margin: 2.0
    procure_method: make_to_stock
    property_stock_inventory: stock.location_inventory
    property_stock_procurement: stock.location_procurement
    property_stock_production: stock.location_production
    seller_delay: '1'
    standard_price: 100.0
    supply_method: buy
    type: product
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
    volume : 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
    reviewed_consumption: 50
    seller_ids:
      - sequence: 10
        min_qty: 0.00
        name: supplier2
        delay: 25
      - sequence: 20
        min_qty: 0.00
        name: supplier1
        delay: 20
-
    I create the product P3
-
  !record {model: product.product, id: product3}:
    categ_id: product_cat1
    cost_method: standard
    mes_type: fixed
    name: P3
    price_margin: 2.0
    procure_method: make_to_stock
    property_stock_inventory: stock.location_inventory
    property_stock_procurement: stock.location_procurement
    property_stock_production: stock.location_production
    seller_delay: '1'
    standard_price: 100.0
    supply_method: buy
    type: product
    uom_id: product.product_uom_unit    
    uom_po_id: product.product_uom_unit
    volume : 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
    reviewed_consumption: 30
    seller_ids:
      - sequence: 10
        min_qty: 0.00
        delay: 30
        name: supplier1
-
    I create the product P4
-
  !record {model: product.product, id: product4}:
    categ_id: product_cat2
    cost_method: standard
    mes_type: fixed
    name: P4
    price_margin: 2.0
    procure_method: make_to_stock
    property_stock_inventory: stock.location_inventory
    property_stock_procurement: stock.location_procurement
    property_stock_production: stock.location_production
    seller_delay: '1'
    standard_price: 100.0
    supply_method: buy
    type: product
    uom_id: product.product_uom_unit    
    uom_po_id: product.product_uom_unit
    volume : 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
    reviewed_consumption: 15
    seller_ids:
      - sequence: 10
        min_qty: 0.00
        delay: 60
        name: supplier1
-
  In order to check the real stock, I will create four SLoc with Sloc3 and Sloc4 which are children of Sloc2
-
  I create the SLoc 1
-
  !record {model: stock.location, id: cycle_sloc1}:
    name: SLoc1
    usage: internal
-
  I create the SLoc 2
-
  !record {model: stock.location, id: cycle_sloc2}:
    name: SLoc2
    usage: internal
-
  I create the SLoc3
-
  !record {model: stock.location, id: cycle_sloc3}:
    name: SLoc3
    usage: internal
    location_id: cycle_sloc2
-
  I create the SLoc4
-
  !record {model: stock.location, id: cycle_sloc4}:
    name: SLoc4
    usage: internal
    location_id: cycle_sloc2
-
  I create a new Warehouse
-
  !record {model: stock.warehouse, id: warehouse_proc_cycle}:
    name: Warehouse Cycle
    lot_stock_id: cycle_sloc2
    lot_input_id: cycle_sloc1
    lot_output_id: stock.stock_location_customers
    company_id: base.main_company
-
  I create a new shop
-
  !record {model: sale.shop, id: shop_cycle}:
    payment_default_id: account.account_payment_term
    name: Cycle Shop
    warehouse_id: warehouse_proc_cycle
-
  I create a batch for product 3 with today + 2 months as expiry date
-
  !record {model: stock.production.lot, id: lot1}:
    name: '0001'
    ref: '0001'
    product_id: product3
- 
  I add the life date on the lot
-
  !python {model: stock.production.lot }: |
    import time
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    req_date = (datetime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') + relativedelta(months=2)).strftime('%Y-%m-%d')
    self.write(cr, uid, ref('lot1'), {'life_date': req_date}, context=context)
-
  I create a batch for product 3 with today + 1 month as expiry date
-
  !record {model: stock.production.lot, id: lot2}:
    name: '0002'
    ref: '0002'
    product_id: product3
- 
  I add the life date on the lot
-
  !python {model: stock.production.lot }: |
    import time
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    req_date = (datetime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') + relativedelta(months=1)).strftime('%Y-%m-%d')
    self.write(cr, uid, ref('lot2'), {'life_date': req_date}, context=context)
-
  I create a batch for product 3 with today + 15 days as expiry date
-
  !record {model: stock.production.lot, id: lot3}:
    name: '0003'
    ref: '0003'
    product_id: product3
- 
  I add the life date on the lot
-
  !python {model: stock.production.lot }: |
    import time
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    req_date = (datetime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') + relativedelta(days=15)).strftime('%Y-%m-%d')
    self.write(cr, uid, ref('lot3'), {'life_date': req_date}, context=context)
-
  I create a batch for product 3 with today + 6 months as expiry date
-
  !record {model: stock.production.lot, id: lot4}:
    name: '0004'
    ref: '0004'
    product_id: product3
- 
  I add the life date on the lot
-
  !python {model: stock.production.lot }: |
    import time
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    req_date = (datetime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') + relativedelta(months=6)).strftime('%Y-%m-%d')
    self.write(cr, uid, ref('lot4'), {'life_date': req_date}, context=context)
-
  I create a batch for product 3 with today + 2 years as expiry date
-
  !record {model: stock.production.lot, id: lot5}:
    name: '0005'
    ref: '0005'
    product_id: product3
- 
  I add the life date on the lot
-
  !python {model: stock.production.lot }: |
    import time
    from datetime import datetime
    from dateutil.relativedelta import relativedelta
    req_date = (datetime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') + relativedelta(years=2)).strftime('%Y-%m-%d')
    self.write(cr, uid, ref('lot5'), {'life_date': req_date}, context=context)
-
  I create an inventory to add products in stock
-
  !record {model: stock.inventory, id: inv1}:
    name: Test Inventory
    company_id: base.main_company
    date: !eval time.strftime('%Y-%m-%d %H:%M:%S')
    date_done: !eval time.strftime('%Y-%m-%d %H:%M:%S')
    inventory_line_id:
      - company_id: base.main_company
        location_id: cycle_sloc1
        product_id: product1
        product_qty: 20.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product1
        product_qty: 32.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc3
        product_id: product1
        product_qty: 15.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc1
        product_id: product2
        product_qty: 12.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product2
        product_qty: 44.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc1
        product_id: product3
        product_qty: 15.0
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product3
        product_qty: 40.0
        prod_lot_id: lot1
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product3
        product_qty: 5.00
        prod_lot_id: lot3
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product3
        product_qty: 250.00
        prod_lot_id: lot4
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product3
        product_qty: 500.00
        prod_lot_id: lot5
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc3
        product_id: product3
        product_qty: 10.0
        prod_lot_id: lot1
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc4
        product_id: product3
        product_qty: 25.0
        prod_lot_id: lot2
        product_uom: product.product_uom_unit
      - company_id: base.main_company
        location_id: cycle_sloc2
        product_id: product4
        product_qty: 12.0
        product_uom: product.product_uom_unit
    state: draft
-
  I confirm the inventory
-
  !python {model: stock.inventory}: |
    self.action_confirm(cr,uid,[ref('inv1')])
    self.action_done(cr,uid,[ref('inv1')])
-
  I check if the availability of P1 is correct
-
  !assert {model: product.product, id: product1}:
    - qty_available == 47.0
    - virtual_available == 47.0
-
  I create a sale order with 15 P1
-
  !record {model: sale.order, id: so1}:
    amount_total: 5.0
    amount_untaxed: 5.0
    date_order: !eval time.strftime('%Y-%m-%d')
    invoice_quantity: order
    order_line:
      - company_id: base.main_company
        name: P1
        delay: 7.0
        price_unit: 12.0
        product_id: product1
        product_uom: product.product_uom_unit
        product_uom_qty: 15.0
        product_uos_qty: 15.0
        state: draft
        type: make_to_order
    order_policy: manual
    partner_id: cust1
    partner_invoice_id: addrc1
    partner_order_id: addrc1
    partner_shipping_id: addrc1
    picking_policy: direct
    pricelist_id: product.list0
    shop_id: shop_cycle
-
  I confirm the Sale Order
-
  !workflow {model: sale.order, action: order_confirm, ref: so1}
-
  I check if the availability of P1 is correct
-
  !assert {model: product.product, id: product1}:
    - qty_available == 47.0
    - virtual_available == 32.0
-
  I check if the availability of P3 is correct
-
  !assert {model: product.product, id: product3}:
    - qty_available == 830.0
    - virtual_available == 830.0
-
  I create a Purchase Order with 35 P3
-
  !record {model: purchase.order, id: po1}:
    company_id: base.main_company
    date_order: !eval time.strftime('%Y-%m-%d')
    invoice_method: order
    location_id: cycle_sloc3
    order_line:
      - date_planned: !eval time.strftime('%Y-%m-%d')
        name: P3
        price_unit: 100.0
        product_id: product3
        product_qty: 35
        product_uom: product.product_uom_unit
        state: draft
    partner_address_id: address1
    partner_id: supplier1
    pricelist_id: purchase.list0
-
  I validate this purchase order
-
  !workflow {model: purchase.order, action: purchase_confirm, ref: po1}
-
  I approve this purchase order
-
  !workflow {model: purchase.order, action: purchase_approve, ref: po1}
-
  I check if the availability of P3 is correct
-
  !assert {model: product.product, id: product3}:
    - qty_available == 830.0
    - virtual_available == 865.0
-
  I crete a new FMC report for Sloc 2
-
  !record {model: monthly.review.consumption, id: mrc2}:
    cons_location_id: cycle_sloc2
    period_from: 2011-01-01
    period_to: !eval time.strftime('%Y-%m-%d')
    line_ids:
      - name: product1
        fmc: 125.0
        valid_ok: True
      - name: product2
        fmc: 236.0
        valid_ok: True
      - name: product3
        fmc: 150.0
        valid_ok: True
-
  I create a new FMC report for Sloc 1
-
  !record {model: monthly.review.consumption, id: mrc1}:
    cons_location_id: cycle_sloc1
    period_from: 2011-01-01
    period_to: !eval time.strftime('%Y-%m-%d')
    line_ids:
      - name: product1
        fmc: 15.0
        valid_ok: True
      - name: product2
        fmc: 45.0
        valid_ok: True
      - name: product3
        fmc: 5.0
        valid_ok: True
-
  I create a stock move for P1 in SLoc 2
- 
  !record {model: stock.move, id: sm_p1_sloc2}:
    name: Product 1 SLoc 2
    product_id: product1
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc2
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 5
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p1_sloc2'), context=context)
    self.action_done(cr, uid, ref('sm_p1_sloc2'), context=context)
-
  I create a stock move for P1 in SLoc 1
- 
  !record {model: stock.move, id: sm_p1_sloc1}:
    name: Product 1 SLoc 1
    product_id: product1
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc1
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 5
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p1_sloc1'), context=context)
    self.action_done(cr, uid, ref('sm_p1_sloc1'), context=context)
-
  I create a stock move for P2 in SLoc 1
- 
  !record {model: stock.move, id: sm_p2_sloc1}:
    name: Product 2 SLoc 1
    product_id: product2
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc1
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 7
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p2_sloc1'), context=context)
    self.action_done(cr, uid, ref('sm_p2_sloc1'), context=context)
-
  I create a stock move for P2 in SLoc 1
- 
  !record {model: stock.move, id: sm_p2_sloc2}:
    name: Product 2 SLoc 2
    product_id: product2
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc2
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 10
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p2_sloc2'), context=context)
    self.action_done(cr, uid, ref('sm_p2_sloc2'), context=context)
-
  I create a stock move for P2 in SLoc 1
- 
  !record {model: stock.move, id: sm_p3_sloc1}:
    name: Product 3 SLoc 1
    product_id: product3
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc1
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 12
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p3_sloc1'), context=context)
    self.action_done(cr, uid, ref('sm_p3_sloc1'), context=context)
-
  I create a stock move for P2 in SLoc 1
- 
  !record {model: stock.move, id: sm_p4_sloc2}:
    name: Product 4 SLoc 2
    product_id: product4
    product_uom: product.product_uom_unit
    date_expected: !eval time.strftime('%Y-%m-%d')
    date: !eval time.strftime('%Y-%m-%d')
    location_id: cycle_sloc2
    location_dest_id: stock.stock_location_customers
    type: out
    reason_type_id: reason_types_moves.reason_type_deliver_partner
    product_qty: 2
-
  I confirm the stock move
-
  !python {model: stock.move}: |
    self.action_confirm(cr, uid, ref('sm_p4_sloc2'), context=context)
    self.action_done(cr, uid, ref('sm_p4_sloc2'), context=context)
