import org.compiere.model.PO; //导入方法依赖的package包/类
@Override
public void copyRecord(final PO po, final String trxName)
{
final PO fromPO;
if (getFromPO_ID() > 0)
{
fromPO = TableModelLoader.instance.getPO(getCtx(), po.get_TableName(), getFromPO_ID(), trxName);
}
else
{
fromPO = po;
}
//
// Copy this level
setBase(true);
final PO toPO;
if (getParentKeyColumn() != null && getParentID() > 0)
{
toPO = TableModelLoader.instance.newPO(getCtx(), fromPO.get_TableName(), trxName);
toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport, this); // need this for getting defaultValues at copy in PO
PO.copyValues(fromPO, toPO, true);
// reset for avoiding copy same object twice
toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport, null);
setBase(false);
// Parent link:
toPO.set_CustomColumn(getParentKeyColumn(), getParentID());
// needs refresh
// not sure if this is still needed
for (final String columnName : toPO.get_KeyColumns())
{
toPO.set_CustomColumn(columnName, toPO.get_Value(columnName));
}
// needs to set IsActive because is not copied
if (toPO.get_ColumnIndex(COLUMNNAME_IsActive) >= 0)
{
toPO.set_CustomColumn(COLUMNNAME_IsActive, fromPO.get_Value(COLUMNNAME_IsActive));
}
// Make sure the columns which are required to be unique they have unique values.
updateSpecialColumnsName(toPO);
// Notify listeners
fireOnRecordCopied(toPO, fromPO);
//
toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport_OldValue, fromPO.get_ID()); // need this for changelog
toPO.saveEx(trxName);
// setParentPO(toPO); // TODO: remove it, not needed
}
else
{
toPO = getParentPO();
}
//
// Copy children
for (final TableInfoVO childTableInfo : getSuggestedChildren(fromPO, getSuggestedChildrenToCopy()))
{
for (final Iterator extends PO> it = retrieveChildPOsForParent(childTableInfo.getTableName(), fromPO); it.hasNext();)
{
final PO childPO = it.next();
final CopyRecordSupport childCRS = CopyRecordFactory.getCopyRecordSupport(childTableInfo.getTableName());
childCRS.setParentKeyColumn(childTableInfo.getLinkColumnName());
childCRS.setAD_Window_ID(getAD_Window_ID());
childCRS.setParentPO(toPO);
childCRS.copyRecord(childPO, trxName);
log.info("Copied {}", childPO);
}
}
}