-
  In order to test mrp_operations module in OpenERP I will put a Production order
  and check its effects on Work orders.
-
  I create a production order.
- 
  !record {model: mrp.production, id: mrp_production_mo0}:
    company_id: base.main_company
    date_planned: '2010-05-25 11:17:34'
    location_dest_id: stock.stock_location_stock
    location_src_id: stock.stock_location_stock
    name: MO/00002
    product_id: product.product_product_pc1
    product_qty: 5.0
    product_uom: product.product_uom_unit
    product_uos_qty: 0.0
- 
  I am computing the data.
- 
  !python {model: mrp.production}: |
    self.action_compute(cr, uid, [ref("mrp_production_mo0")], {"lang": "en_US", "tz":
      False, "search_default_current": 1, "active_model": "ir.ui.menu", "active_ids":
      [ref("mrp.menu_mrp_production_action")], "active_id": ref("mrp.menu_mrp_production_action"),
      })
-
  Now I confirm my production order.
-
  !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_mo0}
-
  I check that there is one Work order generated related to my production order.
-
  !python {model: mrp.production.workcenter.line}: |
    from tools.translate import _
    order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','draft')])
    assert order_id, _('No Work order!')
-
  The scheduler runs.
-
  !function {model: procurement.order, name: run_scheduler}:
    - model: procurement.order
      search: "[('state','=','confirmed')]"
-
  I am checking Internal picking.
-
  !python {model: stock.picking}: |
    from tools.translate import _
    pick_ids = self.search(cr, uid, [('state','!=','done'),('type','=','internal')])
    assert pick_ids, _('No Internal Pickings!')
-
  I see that there is a manufacturing order for the sub product CPU_GEN of PC1 with ready state.
-
  !python {model: mrp.production}: |
    from tools.translate import _
    order_ids = self.search(cr, uid, [('state','=','ready')])
    assert order_ids, _('No new manufacturing order!')
-
  I check that there one more work order created for new production order.
-
  !python {model: mrp.production.workcenter.line}: |
    from tools.translate import _
    prod_obj = self.pool.get('mrp.production')
    prod_order_ids = prod_obj.search(cr, uid, [('state','=','ready')])
    workorder_id = self.search(cr, uid, [('production_id','=', prod_order_ids[0]),('state','=','draft')])
    assert workorder_id, _('No Work order!')
-
  I start the second production order of the CPU_GEN product.
-
  !python {model: mrp.production}: |
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    prod_order_ids = self.search(cr, uid, [('state','=','ready')])
    for po in prod_order_ids:
        wf_service.trg_validate(uid, 'mrp.production', po, 'button_produce', cr)
- 
  I am creating a mrp.product.produce record
-
  !record {model: mrp.product.produce, id: mrp_product_produce_0}:
    mode: consume_produce
    product_qty: 5.0
- 
  I produce the product CPU_GEN.
-
  !python {model: mrp.product.produce}: |
    prod_obj = self.pool.get('mrp.production')
    prod_order_ids = prod_obj.search(cr, uid, [('state','=','in_production')])
    self.do_produce(cr, uid, [ref("mrp_product_produce_0")], {"lang": "en_US", "tz":
      False, "search_default_current": 1, "active_model": "mrp.production", "active_ids":
      prod_order_ids, "active_id": prod_order_ids[0], })
-
  I check that my production order and its related work order is in done state.
-
  !python {model: mrp.production.workcenter.line}: |
    from tools.translate import _
    prod_obj = self.pool.get('mrp.production')
    prod_order_ids = prod_obj.search(cr, uid, [('state','=','done')])
    workorder_id = self.search(cr, uid, [('production_id','=', prod_order_ids[0]),('state','=','done')])
    assert workorder_id, _('Work order is not done!')
-
  Now I check my original production order is now ready.
-
  !python {model: mrp.production}: |
    from tools.translate import _
    prod_ids = self.search(cr, uid, [('id','=',ref('mrp_production_mo0')),('state','=','ready')])
    assert prod_ids, _('Production order is not ready!')
-
  I check that both internal pickings are done.
-
  !python {model: stock.picking}: |
    from tools.translate import _    
    pick_ids = self.search(cr, uid, [('state','=','done'),('type','=','internal')])
    assert pick_ids, _('Internal pickings are not done!')
-
  Now I start my first production order.
-
  !workflow {model: mrp.production, action: button_produce, ref: mrp_production_mo0}      
-
  I check that the related work order is in progress state.    
-
  !python {model: mrp.production.workcenter.line}: |    
    from tools.translate import _
    order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','startworking')])
    assert order_id, _('Work order not started yet!')
-
  I am creating a mrp.product.produce record.
-
  !record {model: mrp.product.produce, id: mrp_product_produce_0}:
    mode: consume_produce
    product_qty: 5.0
- 
  I produce the product PC1.
-
  !python {model: mrp.product.produce}: |
    prod_obj = self.pool.get('mrp.production')
    prod_order_ids = prod_obj.search(cr, uid, [('state','=','in_production')])
    self.do_produce(cr, uid, [ref("mrp_product_produce_0")], {"lang": "en_US", "tz":
      False, "search_default_current": 1, "active_model": "mrp.production", "active_ids":
      [ref("mrp_production_mo0")], "active_id": ref("mrp_production_mo0"), })
-
  I check the related work order is done.
-
  !python {model: mrp.production.workcenter.line}: |    
    from tools.translate import _
    order_id = self.search(cr, uid, [('production_id','=', ref('mrp_production_mo0')),('state','=','done')])
    assert order_id, _('Work order not done yet!')   
