Fix #19 Verify BOM button in product window is not working

Bringing some libero classes to core to preserve backward compatibility without MFG
CopyFromBOM.java and PP_Product_BOM_Check.java developed by teo_sarca according to mercurial logs
This commit is contained in:
Carlos Ruiz 2011-05-13 18:26:55 -05:00
parent c2b2b7232a
commit 3880ea8b78
4 changed files with 241 additions and 0 deletions

View File

@ -0,0 +1,9 @@
-- May 13, 2011 5:57:53 PM COT
-- iDempiere fixes on core BOM management
UPDATE AD_Tab SET WhereClause=NULL, AD_Column_ID=53333, Parent_Column_ID=NULL,Updated=TO_DATE('2011-05-13 17:57:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=53286
;
-- May 13, 2011 5:58:09 PM COT
UPDATE AD_Tab SET AD_Column_ID=53366,Updated=TO_DATE('2011-05-13 17:58:09','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=53287
;

View File

@ -0,0 +1,9 @@
-- May 13, 2011 5:57:53 PM COT
-- iDempiere fixes on core BOM management
UPDATE AD_Tab SET WhereClause=NULL, AD_Column_ID=53333, Parent_Column_ID=NULL,Updated=TO_TIMESTAMP('2011-05-13 17:57:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=53286
;
-- May 13, 2011 5:58:09 PM COT
UPDATE AD_Tab SET AD_Column_ID=53366,Updated=TO_TIMESTAMP('2011-05-13 17:58:09','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=53287
;

View File

@ -0,0 +1,97 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. *
* Contributor(s): Victor Perez www.e-evolution.com *
*****************************************************************************/
package org.eevolution.process;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.Env;
import org.eevolution.model.MPPProductBOM;
import org.eevolution.model.MPPProductBOMLine;
/**
* CopyFromBOM Process
* Copies BOM Lines from Selected BOM to the Current BOM
* The BOM being copied to must have no pre-existing BOM Lines
*
* @author Tony Snook
* @version $Id: CopyFromBOM.java,v 1.0 2008/07/04 05:24:03 tspc Exp $
*/
public class CopyFromBOM extends SvrProcess {
/** */
private int p_Record_ID = 0;
private int p_PP_Product_BOM_ID = 0;
private int no = 0;
private Properties ctx = Env.getCtx();
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++) {
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("PP_Product_BOM_ID"))
p_PP_Product_BOM_ID = para[i].getParameterAsInt();
else
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
}
p_Record_ID = getRecord_ID();
} // prepare
protected String doIt() throws Exception
{
log.info("From PP_Product_BOM_ID=" + p_PP_Product_BOM_ID + " to " + p_Record_ID);
if (p_Record_ID == 0)
throw new IllegalArgumentException("Target PP_Product_BOM_ID == 0");
if (p_PP_Product_BOM_ID == 0)
throw new IllegalArgumentException("Source PP_Product_BOM_ID == 0");
if (p_Record_ID == p_PP_Product_BOM_ID)
return "";
MPPProductBOM fromBom = new MPPProductBOM(ctx, p_PP_Product_BOM_ID, get_TrxName());
MPPProductBOM toBOM = new MPPProductBOM(ctx, p_Record_ID, get_TrxName());
if (toBOM.getLines().length > 0)
{
throw new AdempiereSystemError("@Error@ Existing BOM Line(s)");
}
MPPProductBOMLine[] frombomlines = fromBom.getLines();
for (MPPProductBOMLine frombomline : frombomlines)
{
MPPProductBOMLine tobomline = new MPPProductBOMLine(ctx, 0, get_TrxName());
MPPProductBOMLine.copyValues(frombomline, tobomline);
tobomline.setPP_Product_BOM_ID(toBOM.getPP_Product_BOM_ID());
tobomline.save();
++no;
}
return "OK";
}
@Override
protected void postProcess(boolean success)
{
this.addLog("@Copied@=" + no);
}
}

View File

@ -0,0 +1,126 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
* Portions created by Carlos Ruiz are Copyright (C) 2005 QSS Ltda.
* Contributor(s): Carlos Ruiz (globalqss)
*****************************************************************************/
package org.eevolution.process;
import java.util.logging.Level;
import org.compiere.model.MProduct;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.AdempiereUserError;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.ValueNamePair;
import org.eevolution.model.MPPProductBOM;
import org.eevolution.model.MPPProductBOMLine;
/**
* Title: Check BOM Structure (free of cycles) Description: Tree cannot contain
* BOMs which are already referenced
*
* @author Tony Snook (tspc)
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*/
public class PP_Product_BOM_Check extends SvrProcess
{
/** The Record */
private int p_Record_ID = 0;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
p_Record_ID = getRecord_ID();
} // prepare
/**
* Process
*
* @return message
* @throws Exception
*/
protected String doIt() throws Exception
{
log.info("Check BOM Structure");
// Record ID is M_Product_ID of product to be tested
MProduct xp = new MProduct(Env.getCtx(), p_Record_ID, get_TrxName());
if (!xp.isBOM())
{
log.info("Product is not a BOM");
// No BOM - should not happen, but no problem
return "OK";
}
// Check Parent Level
int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), p_Record_ID, get_TrxName());
xp.setLowLevel(lowlevel);
xp.setIsVerified(true);
xp.saveEx();
// Get Default BOM from this product
MPPProductBOM tbom = MPPProductBOM.getDefault(xp, get_TrxName());
if (tbom == null) {
raiseError("No Default BOM found: ", "Check BOM Parent search key");
}
// Check All BOM Lines
if (tbom.getM_Product_ID() != 0)
{
MPPProductBOMLine[] tbomlines = tbom.getLines();
for (MPPProductBOMLine tbomline : tbomlines)
{
lowlevel = tbomline.getLowLevel();
MProduct p = new MProduct(getCtx(), tbomline.getM_Product_ID(), get_TrxName());
p.setLowLevel(lowlevel);
p.setIsVerified(true);
p.saveEx();
}
}
return "OK";
} // doIt
private void raiseError(String string, String hint) throws Exception
{
DB.rollback(false, get_TrxName());
MProduct xp = new MProduct(getCtx(), p_Record_ID, null); // parent
xp.setIsVerified(false); // set BOM not verified
xp.saveEx();
String msg = string;
ValueNamePair pp = CLogger.retrieveError();
if (pp != null)
msg = pp.getName() + " - ";
msg += hint;
throw new AdempiereUserError(msg);
}
} // M_Product_BOM_Check