FR [3067850] - Bug coping details from other Project

http://sourceforge.net/support/tracker.php?aid=3067850
This commit is contained in:
monhate 2011-03-26 01:20:18 -05:00
parent 9687466c7f
commit 9de87fea93
3 changed files with 138 additions and 12 deletions

View File

@ -33,11 +33,10 @@ import org.compiere.util.Env;
*/
public class MProject extends X_C_Project
{
/**
*
*/
private static final long serialVersionUID = -1781787100948563589L;
private static final long serialVersionUID = 2151648902207548617L;
/**
* Create new Project by copying
@ -279,6 +278,10 @@ public class MProject extends X_C_Project
MProjectLine[] fromLines = project.getLines();
for (int i = 0; i < fromLines.length; i++)
{
//BF 3067850 - monhate
if((fromLines[i].getC_ProjectPhase_ID() != 0)||
(fromLines[i].getC_ProjectTask_ID() != 0)) continue;
MProjectLine line = new MProjectLine (getCtx(), 0, project.get_TrxName());
PO.copyValues(fromLines[i], line, getAD_Client_ID(), getAD_Org_ID());
line.setC_Project_ID(getC_Project_ID());
@ -306,7 +309,7 @@ public class MProject extends X_C_Project
if (isProcessed() || fromProject == null)
return 0;
int count = 0;
int taskCount = 0;
int taskCount = 0, lineCount = 0;
// Get Phases
MProjectPhase[] myPhases = getPhases();
MProjectPhase[] fromPhases = fromProject.getPhases();
@ -343,13 +346,15 @@ public class MProject extends X_C_Project
{
count++;
taskCount += toPhase.copyTasksFrom (fromPhases[i]);
//BF 3067850 - monhate
lineCount += toPhase.copyLinesFrom(fromPhases[i]);
}
}
}
if (fromPhases.length != count)
log.warning("Count difference - Project=" + fromPhases.length + " <> Saved=" + count);
return count + taskCount;
return count + taskCount + lineCount;
} // copyPhasesFrom
@ -459,4 +464,17 @@ public class MProject extends X_C_Project
return success;
} // afterDelete
/**
* Return the Invoices Generated for this Project
* @return invoices
* @author monhate
*/
public MInvoice[] getMInvoices(){
StringBuilder sb = new StringBuilder();
sb.append(MInvoice.COLUMNNAME_C_Project_ID).append("=?");
Query qry = new Query(getCtx(), MInvoice.Table_Name, sb.toString(), get_TrxName());
qry.setParameters(getC_Project_ID());
return (MInvoice[]) qry.list().toArray();
}
} // MProject

View File

@ -20,6 +20,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -37,7 +38,7 @@ public class MProjectPhase extends X_C_ProjectPhase
/**
*
*/
private static final long serialVersionUID = 3445836323245259566L;
private static final long serialVersionUID = 5824045445920353065L;
/**
* Standard Constructor
@ -142,9 +143,40 @@ public class MProjectPhase extends X_C_ProjectPhase
return retValue;
} // getTasks
/**
* Copy Lines from other Phase
* BF 3067850 - monhate
* @param fromPhase from phase
* @return number of tasks copied
*/
public int copyLinesFrom (MProjectPhase fromPhase)
{
if (fromPhase == null)
return 0;
int count = 0;
//
MProjectLine[] fromLines = fromPhase.getLines();
// Copy Project Lines
for (int i = 0; i < fromLines.length; i++)
{
if(fromLines[i].getC_ProjectTask_ID() != 0) continue;
MProjectLine toLine = new MProjectLine(getCtx (), 0, get_TrxName());
PO.copyValues (fromLines[i], toLine, getAD_Client_ID (), getAD_Org_ID ());
toLine.setC_Project_ID(getC_Project_ID ());
toLine.setC_ProjectPhase_ID (getC_ProjectPhase_ID ());
if (toLine.save ())
count++;
}
if (fromLines.length != count)
log.warning("Count difference - ProjectLine=" + fromLines.length + " <> Saved=" + count);
return count;
}
/**
* Copy Tasks from other Phase
* BF 3067850 - monhate
* @param fromPhase from phase
* @return number of tasks copied
*/
@ -152,7 +184,7 @@ public class MProjectPhase extends X_C_ProjectPhase
{
if (fromPhase == null)
return 0;
int count = 0;
int count = 0, countLine = 0;
//
MProjectTask[] myTasks = getTasks();
MProjectTask[] fromTasks = fromPhase.getTasks();
@ -183,14 +215,17 @@ public class MProjectPhase extends X_C_ProjectPhase
MProjectTask toTask = new MProjectTask (getCtx (), 0, get_TrxName());
PO.copyValues (fromTasks[i], toTask, getAD_Client_ID (), getAD_Org_ID ());
toTask.setC_ProjectPhase_ID (getC_ProjectPhase_ID ());
if (toTask.save ())
if (toTask.save ()){
count++;
//BF 3067850 - monhate
countLine += toTask.copyLinesFrom(fromTasks[i]);
}
}
}
if (fromTasks.length != count)
log.warning("Count difference - ProjectPhase=" + fromTasks.length + " <> Saved=" + count);
return count;
return count + countLine;
} // copyTasksFrom
/**
@ -218,6 +253,23 @@ public class MProjectPhase extends X_C_ProjectPhase
return count;
} // copyTasksFrom
/**************************************************************************
* Get Project Lines
* BF 3067850 - monhate
* @return Array of lines
*/ public MProjectLine[] getLines()
{
final String whereClause = "C_Project_ID=? and C_ProjectPhase_ID=?";
List <MProjectLine> list = new Query(getCtx(), I_C_ProjectLine.Table_Name, whereClause, get_TrxName())
.setParameters(getC_Project_ID(), getC_ProjectPhase_ID())
.setOrderBy("Line")
.list();
//
MProjectLine[] retValue = new MProjectLine[list.size()];
list.toArray(retValue);
return retValue;
}
/**
* String Representation
* @return info

View File

@ -17,6 +17,7 @@
package org.compiere.model;
import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import org.compiere.util.Env;
@ -32,7 +33,7 @@ public class MProjectTask extends X_C_ProjectTask
/**
*
*/
private static final long serialVersionUID = -4031011454351572357L;
private static final long serialVersionUID = 6714520156233475723L;
/**
* Standard Constructor
@ -95,6 +96,61 @@ public class MProjectTask extends X_C_ProjectTask
setQty(task.getStandardQty());
} // MProjectTask
/**************************************************************************
* Get Project Lines
* BF 3067850 - monhate
* @return Array of lines
*/ public MProjectLine[] getLines()
{
final String whereClause = "C_ProjectPhase_ID=? and C_ProjectTask_ID=? ";
List <MProjectLine> list = new Query(getCtx(), I_C_ProjectLine.Table_Name, whereClause, get_TrxName())
.setParameters(getC_ProjectPhase_ID(), getC_ProjectTask_ID())
.setOrderBy("Line")
.list();
//
MProjectLine[] retValue = new MProjectLine[list.size()];
list.toArray(retValue);
return retValue;
}
/**
* Copy Lines from other Task
* BF 3067850 - monhate
* @param fromTask from Task
* @return number of lines copied
*/
public int copyLinesFrom (MProjectTask fromTask)
{
if (fromTask == null)
return 0;
int count = 0;
//
MProjectLine[] fromLines = fromTask.getLines();
// Copy Project Lines
for (int i = 0; i < fromLines.length; i++)
{
MProjectLine toLine = new MProjectLine(getCtx (), 0, get_TrxName());
PO.copyValues (fromLines[i], toLine, getAD_Client_ID (), getAD_Org_ID ());
toLine.setC_Project_ID(getC_Project_ID(false));
toLine.setC_ProjectPhase_ID (getC_ProjectPhase_ID ());
toLine.setC_ProjectTask_ID(getC_ProjectTask_ID ());
if (toLine.save ())
count++;
}
if (fromLines.length != count)
log.warning("Count difference - ProjectLine=" + fromLines.length + " <> Saved=" + count);
return count;
}
private int C_Project_ID = 0;
private int getC_Project_ID(boolean reQuery) {
if (C_Project_ID==0 || reQuery)
C_Project_ID = getC_ProjectPhase().getC_Project_ID();
return C_Project_ID;
}
/**
* String Representation
* @return info