CREATE OR REPLACE FUNCTION ip_seed_orderline (p_id numeric, p_num numeric)
RETURNS integer AS
$BODY$
DECLARE 
	i	integer;
BEGIN

	/*
	better to start with small portions
		select ip_seed_orderline(1000000, 2000)
	than once 1 million.
	*/
	i := 1;
	WHILE i < p_num
	LOOP
		insert into c_orderline (c_orderline_id, ad_client_id, ad_org_id, created, createdby, updated, updatedby, isactive, c_order_id, m_product_id, c_uom_id, m_warehouse_id, c_currency_id, qtyentered, priceentered, priceactual, c_tax_id, pricelist, linenetamt, line, dateordered, c_bpartner_id, c_bpartner_location_id )
		select nextid (233,'N'), ad_client_id, ad_org_id, created, createdby, updated, updatedby, isactive, c_order_id, m_product_id, c_uom_id, m_warehouse_id, c_currency_id, qtyentered, priceentered, priceactual, c_tax_id, pricelist, linenetamt, line, dateordered, c_bpartner_id, c_bpartner_location_id from c_orderline where c_orderline_id = p_id;

		i := i+1;
	END LOOP;
	
	RETURN 1;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION ip_seed_orderline(numeric, numeric)
  OWNER TO adempiere;
