Search in sources :

Example 56 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class SqlDocumentsRepository method save.

@Override
public void save(final Document document) {
    Services.get(ITrxManager.class).assertThreadInheritedTrxExists();
    assertThisRepository(document.getEntityDescriptor());
    DocumentPermissionsHelper.assertCanEdit(document);
    // Runnables to be executed after the PO is saved
    final List<Runnable> afterSaveRunnables = new ArrayList<>();
    // 
    // Load the PO / Create new PO instance
    final PO po = retrieveOrCreatePO(document);
    // 
    // Set values to PO
    final boolean isNew = document.isNew();
    boolean changes = false;
    for (final IDocumentFieldView documentField : document.getFieldViews()) {
        if (!isNew && !documentField.hasChangesToSave()) {
            logger.trace("Skip setting PO value because document field has no changes: {}", documentField);
            continue;
        }
        if (DocumentFieldWidgetType.Labels == documentField.getWidgetType()) {
            // save labels after PO is saved because we want to make sure it's not new (so we can link to it)
            afterSaveRunnables.add(() -> saveLabels(document, documentField));
        }
        if (setPOValue(po, documentField)) {
            changes = true;
        }
    }
    // 
    // Save the PO
    boolean needsRefresh = false;
    if (changes) {
        // 
        // Actual save
        // TODO: advice the PO to not reload after save.
        InterfaceWrapperHelper.save(po);
        document.markAsNotNew();
        needsRefresh = true;
    } else {
        logger.trace("Skip saving {} because there was no actual change", po);
    }
    // Execute after save runnables
    if (!afterSaveRunnables.isEmpty()) {
        afterSaveRunnables.forEach(r -> r.run());
        needsRefresh = true;
    }
    // Reload the document
    if (needsRefresh) {
        final SqlDocumentEntityDataBindingDescriptor dataBinding = document.getEntityDescriptor().getDataBinding(SqlDocumentEntityDataBindingDescriptor.class);
        final DocumentId idNew = extractDocumentId(po, dataBinding);
        refresh(document, idNew);
    }
    // Notify the parent document that one of it's children were saved
    if (!document.isRootDocument()) {
        document.getParentDocument().onChildSaved(document);
    }
}
Also used : ITrxManager(org.adempiere.ad.trx.api.ITrxManager) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) ArrayList(java.util.ArrayList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) PO(org.compiere.model.PO)

Example 57 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowFactoryTest method test.

@Test
public void test() {
    final PurchaseCandidate purchaseCandidate = createPurchaseCandidate(30);
    final PurchaseRowFactory purchaseRowFactory = new PurchaseRowFactory();
    final PurchaseRow candidateRow = purchaseRowFactory.rowFromPurchaseCandidateBuilder().purchaseCandidate(purchaseCandidate).vendorProductInfo(purchaseCandidate.getVendorProductInfo()).datePromised(SystemTime.asTimestamp()).build();
    final DocumentId id = candidateRow.getId();
    final PurchaseRowId purchaseRowId = PurchaseRowId.fromDocumentId(id);
    assertThat(purchaseRowId.getVendorBPartnerId()).isEqualTo(purchaseCandidate.getVendorBPartnerId());
    assertThat(purchaseRowId.getSalesOrderLineId()).isEqualTo(purchaseCandidate.getSalesOrderLineId());
    assertThat(purchaseRowId.getProcessedPurchaseCandidateId()).isEqualTo(30);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PurchaseCandidate(de.metas.purchasecandidate.PurchaseCandidate) Test(org.junit.Test)

Example 58 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowIdTest method groupId.

@Test
public void groupId() {
    final PurchaseRowId rowId = PurchaseRowId.groupId(20);
    final DocumentId documentId = rowId.toDocumentId();
    assertThat(documentId.toString()).isEqualTo("20");
    assertThat(rowId.isGroupRowId()).isTrue();
    assertThat(rowId.isLineRowId()).isFalse();
    assertThat(rowId.isAvailabilityRowId()).isFalse();
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Example 59 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowIdTest method fromDocumentId_Available.

@Test
public void fromDocumentId_Available() {
    final DocumentId documentId = DocumentId.ofString("1000007-2156423-0-AVAILABLE-11");
    final PurchaseRowId purchaseRowId = PurchaseRowId.fromDocumentId(documentId);
    assertThat(purchaseRowId.getSalesOrderLineId()).isEqualTo(1000007);
    assertThat(purchaseRowId.getVendorBPartnerId()).isEqualTo(2156423);
    assertThat(purchaseRowId.getProcessedPurchaseCandidateId()).isEqualTo(0);
    assertThat(purchaseRowId.getAvailabilityType()).isEqualTo(Type.AVAILABLE);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Example 60 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.

the class PurchaseRowIdTest method lineId_performWithParams.

private void lineId_performWithParams(final String salesOrderLineId, final String vendorBPartnerId, final String processedPurchaseCandidateId) {
    final PurchaseRowId rowId = PurchaseRowId.lineId(Integer.parseInt(salesOrderLineId), Integer.parseInt(vendorBPartnerId), Integer.parseInt(processedPurchaseCandidateId));
    final DocumentId documentId = rowId.toDocumentId();
    assertThat(documentId.toString()).isEqualTo(salesOrderLineId + PurchaseRowId.PARTS_SEPARATOR + vendorBPartnerId + PurchaseRowId.PARTS_SEPARATOR + processedPurchaseCandidateId);
    assertThat(rowId.isGroupRowId()).isFalse();
    assertThat(rowId.isLineRowId()).isTrue();
    assertThat(rowId.isAvailabilityRowId()).isFalse();
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8