PO Lines Creating

1.無需設Discount,LineNetAmt,因爲OrderLine beforeSave()會設定。

2.setC_UOM_ID放到setPrice()之後,如果UOM不想從產品取。

3.如果價格不是自定義,可以直接調用setPrice().

-----

 

POLineCreate .java
package  org.compiere.process;

import  java.io.BufferedReader;
import  java.io.FileReader;
import  java.math.BigDecimal;

import  org.compiere.model.MOrder;
import  org.compiere.model.MOrderLine;
import  org.compiere.model.MPriceList;
import  org.compiere.model.MProduct;
import  org.compiere.model.MUOMConversion;
import  org.compiere.util.DB;
import  org.compiere.util.Env;

/**
 *  Delete PO Lines
 *
 *  
@author Stephy Shum
 *  
@version  $Id: POLineCreate.java,v 1.2 2007/10/17  trifonnt Exp $
 
*/

public   class  POLineCreate  extends  SvrProcess {
  
/**
   *  Prepare - e.g., get Parameters.
   
*/

  
protected void prepare()
  
{
   
  }


  
/**
   *  Perrform process.
   *  
@return Message
   *  
@throws Exception
   
*/

  
protected String doIt() throws Exception
  
{
   String directory 
= org.compiere.Compiere.getCompiereHome();
   BufferedReader in 
= new BufferedReader(new FileReader(directory+"/data/import/POLinesCreate.csv")); //read POLinesDelete.csv
   String s=null;
   String documentno
="";
   MOrder po
=null;
   
int C_Order_ID=0;
   
int AD_Client_ID=Env.getAD_Client_ID(Env.getCtx());
   
int created=0;
   
int nocreated=0;
   
   
while ((s = in.readLine()) != null){
    System.out.println(
"===s==="+s);
    String splits[]
=s.split(",");
    
//splits[0] - Document no 
    
//splits[1] - Purchase For
    
//splits[2] - Product 
    
//splits[3] - UOM 
    
//splits[4] - Quantity
    
//splits[5] - Price
    if(!splits[0].equals(documentno))//diffrence documentno
     documentno=splits[0];
     C_Order_ID
=DB.getSQLValue(get_TrxName(),"SELECT C_Order_ID FROM C_Order WHERE Documentno='"+documentno+"' AND AD_Client_ID=?",AD_Client_ID);
     
if(C_Order_ID<=0)
      
continue;  //May be line 1
     po=new MOrder(Env.getCtx(),C_Order_ID,get_TrxName());
    }

    
//Create PO Lines
    MOrderLine poline=new MOrderLine(po);
    
int C_PurchaseFor_ID=DB.getSQLValue(get_TrxName(),"SELECT C_PurchaseFor_ID FROM C_PurchaseFor where Name='"+splits[1]+"' AND AD_Client_ID=?",AD_Client_ID);
    
int M_Product_ID=DB.getSQLValue(get_TrxName(),"SELECT M_Product_ID FROM M_Product WHERE value='"+splits[2]+"' AND AD_Client_ID=?",AD_Client_ID);
    
int C_UOM_ID=DB.getSQLValue(get_TrxName(),"SELECT C_UOM_ID FROM C_UOM WHERE name='"+splits[3]+"' AND AD_Client_ID=?",AD_Client_ID);
    BigDecimal qty
=new BigDecimal(splits[4]);
    BigDecimal price
=new BigDecimal(splits[5]);
    poline.setM_Product_ID(M_Product_ID);
//1
    
//poline.setM_AttributeSetInstance_ID();
    poline.setQtyEntered(qty);
    poline.setQtyOrdered(qty);
    poline.setPriceActual(price);
    poline.setPriceList(price);
    poline.setPriceLimit(price);
    poline.setPriceEntered(price.setScale(
2, BigDecimal.ROUND_HALF_UP));
    poline.setC_PurchaseFor_ID(C_PurchaseFor_ID); 
// @Trifon
    poline.setLine(DB.getSQLValue(get_TrxName(),"SELECT NVL(MAX(Line),0)+10 AS DefaultValue FROM C_OrderLine WHERE C_Order_ID=?",C_Order_ID));
    poline.setC_UOM_ID(C_UOM_ID);
    
// set OK
    
// UOM Conversion?
    MProduct product=new MProduct(Env.getCtx(),M_Product_ID,get_TrxName());
    
if(product.getC_UOM_ID()!=C_UOM_ID){
     BigDecimal PriceActual
=MUOMConversion.convertProductFrom (Env.getCtx(), M_Product_ID, 
       C_UOM_ID, poline.getPriceActual());
     BigDecimal QtyOrdered 
= MUOMConversion.convertProductFrom (Env.getCtx(), M_Product_ID, 
       C_UOM_ID, qty);
     
if(PriceActual!=null)
      poline.setPriceEntered(PriceActual.setScale(
2, BigDecimal.ROUND_HALF_UP));
     
if(QtyOrdered!=null)
      poline.setQtyOrdered(QtyOrdered);
     
//no check price limited
    }

    
if(poline.save()){
     System.out.println(
"====OK====");
     created
++;
    }

    
else{
     System.out.println(
"====save error!====");
     nocreated
++;
    }

     
   }

   
return "Created "+created+" no Created "+nocreated;
  }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值