use of org.adempiere.model.CopyRecordSupport in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method duplicateDocumentInTrx.
private DocumentPath duplicateDocumentInTrx(final DocumentPath fromDocumentPath) {
// NOTE: assume it's already running in transaction
final TableRecordReference fromRecordRef = getTableRecordReference(fromDocumentPath);
final Object fromModel = fromRecordRef.getModel(PlainContextAware.newWithThreadInheritedTrx());
final String tableName = InterfaceWrapperHelper.getModelTableName(fromModel);
final PO fromPO = InterfaceWrapperHelper.getPO(fromModel);
final PO toPO = TableModelLoader.instance.newPO(Env.getCtx(), tableName, ITrx.TRXNAME_ThreadInherited);
// set "getValueToCopy" advisor
toPO.setDynAttribute(PO.DYNATTR_CopyRecordSupport, CopyRecordFactory.getCopyRecordSupport(tableName));
PO.copyValues(fromPO, toPO, true);
InterfaceWrapperHelper.save(toPO);
final CopyRecordSupport childCRS = CopyRecordFactory.getCopyRecordSupport(tableName);
childCRS.setAD_Window_ID(fromDocumentPath.getAD_Window_ID(-1));
childCRS.setParentPO(toPO);
childCRS.setBase(true);
childCRS.copyRecord(fromPO, ITrx.TRXNAME_ThreadInherited);
final DocumentPath toDocumentPath = DocumentPath.rootDocumentPath(fromDocumentPath.getWindowId(), DocumentId.of(toPO.get_ID()));
return toDocumentPath;
}
Aggregations