-
  Create a Sale Order
-
  !record {model: sale.order, id: so_A}:
    company_id: base.main_company
    date_order: '2011-04-13'
    invoice_quantity: order
    order_policy: manual
    partner_id: partner_A
    partner_invoice_id: address_A
    partner_order_id: address_A
    partner_shipping_id: address_A
    picking_policy: direct
    pricelist_id: product.list0
    shop_id: sale.shop
    priority: normal
    categ: medical
-
  Create a Sale Order Line
-
  !record {model: sale.order.line, id: sol_A1}:
    product_uom: product.product_uom_unit
    product_id: product_A
    order_id: so_A
    price_unit: 1
    product_uom_qty: 10
    date_planned: '2011-04-13'
    type: make_to_order
-
  !record {model: sale.order.line, id: sol_A2}:
    product_uom: product.product_uom_unit
    product_id: product_B
    order_id: so_A
    price_unit: 1
    product_uom_qty: 5
    date_planned: '2011-04-13'
    type: make_to_order
-
  I validate the sale order
-
  !python {model: sale.order}: |
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'sale.order', ref("so_A"), 'order_confirm', cr)
-
  Run the scheduler
-
  !python {model: procurement.order}: |
    self.run_scheduler(cr, uid)
-
  Validate the purchase order
-
  !python {model: purchase.order}: |
    proc_obj = self.pool.get('procurement.order')
    sol_obj = self.pool.get('sale.order.line')
    # get the corresponding procurement order
    data = sol_obj.read(cr, uid, [ref("sol_A1")], ['procurement_id'], context=context)[0]
    assert data['procurement_id'], 'the procurement is missing, problem in procurement generation'
    proc_id = data['procurement_id'][0]
    data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
    assert data['purchase_id'], 'purchase data is missing, problem in purchase generation'
    po_id = data['purchase_id'][0]
    # change Invoicing control to From Picking
    self.write(cr, uid, [po_id], {'invoice_method':'picking'}, context=context)
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_confirm', cr)
    wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_approve', cr)
-
  Process the incoming shipment
-
  !python {model: stock.picking}: |
    proc_obj = self.pool.get('procurement.order')
    sol_obj = self.pool.get('sale.order.line')
    # get the corresponding procurement order
    data = sol_obj.read(cr, uid, [ref("sol_A1")], ['procurement_id'], context=context)[0]
    proc_id = data['procurement_id'][0]
    data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
    po_id = data['purchase_id'][0]
    # find the IN


    in_ids = self.search(cr, uid, [('purchase_id', '=', po_id)], context=context)

    dic = self.action_process(cr, uid, in_ids, context=context)

    self.pool.get(dic['res_model']).copy_all(cr,uid, [dic['res_id']], context=dic['context'])

    self.pool.get(dic['res_model']).do_incoming_shipment(cr, uid, [dic['res_id']], context=dic['context'])



    data = self.read(cr, uid, in_ids, ['state'], context=context)[0]
    assert data['state'] == 'done', 'the incoming shipment is not Done - done - %s'%data['state']
    
