Search in sources :

Example 1 with CopyRecordSupport

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;
}
Also used : CopyRecordSupport(org.adempiere.model.CopyRecordSupport) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) PO(org.compiere.model.PO)

Aggregations

DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 CopyRecordSupport (org.adempiere.model.CopyRecordSupport)1 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)1 PO (org.compiere.model.PO)1