@Override public String modelChange(final PO po, final int type) throws Exception { if (type == TYPE_BEFORE_CHANGE) { final I_C_Order order = InterfaceWrapperHelper.create(po, I_C_Order.class); if (po.is_ValueChanged(I_C_Invoice_Candidate.COLUMNNAME_DateOrdered)) { final IOrderPA orderPA = Services.get(IOrderPA.class); final IInvoiceCandDAO invoiceCandDB = Services.get(IInvoiceCandDAO.class); for (final I_C_OrderLine ol : orderPA.retrieveOrderLines(order, I_C_OrderLine.class)) { for (final I_C_Invoice_Candidate icOfOl : invoiceCandDB.retrieveReferencing(ol)) { if (icOfOl.isToClear()) { // If the column was updatable, we would have to // *check if new and old term are the same // *check if ICAs need update, creation or deletion and do it; // *check which dataEntries' ActualQty needs update and make sure that they are not // yet // completed // *check is isToClear needs update; throw new AdempiereException( Env.getAD_Language(po.getCtx()), MSG_ORDER_DATE_ORDERED_CHANGE_FORBIDDEN_1P, new Object[] {ol.getLine()}); } } } } } return null; }
private void checkInvoicingDataEntry( final I_C_Order order, final I_C_Flatrate_DataEntry dataEntry, final I_C_Flatrate_Term term) { assertThat(dataEntry.isSimulation(), equalTo(term.isSimulation())); assertThat(term.getC_Flatrate_Term_ID(), equalTo(dataEntry.getC_Flatrate_Term_ID())); final TestConfig testConfig = helper.getConfig(); final boolean paramIsSimulation = testConfig.getCustomParamBool(FlatFeeScenario.PARAM_BOOL_IS_SIMULATION); final IFlatrateDAO flatrateDB = Services.get(IFlatrateDAO.class); BigDecimal sum = BigDecimal.ZERO; final boolean dataEntryCompleted = dataEntry.getDocStatus().equals(X_C_Flatrate_DataEntry.DOCSTATUS_Completed); final List<I_C_Invoice_Clearing_Alloc> clearingAllocs = flatrateDB.retrieveClearingAllocs(dataEntry); if (paramIsSimulation) { assertThat( "Expected *no* C_Invoice_Clearing_Allocs for " + dataEntry, clearingAllocs.size(), equalTo(0)); } else { // note that we expect the C_Invoice_Clearing_Allocs no matter whether 'dataEntry' has already // been // completed assertThat( "Expected C_Invoice_Clearing_Allocs for " + dataEntry, clearingAllocs.size(), greaterThan(0)); } for (final MOrderLine ol : driver.getHelper().mkOrderHelper().getOrderPO(order).getLines(true, null)) { for (final I_C_Invoice_Clearing_Alloc ica : clearingAllocs) { assertThat(ica.getC_Invoice_Cand_ToClear_ID(), greaterThan(0)); assertThat(ica.getC_Flatrate_Term_ID(), equalTo(term.getC_Flatrate_Term_ID())); assertThat( ica.getC_Flatrate_DataEntry_ID(), equalTo(dataEntry.getC_Flatrate_DataEntry_ID())); final I_C_Invoice_Candidate icToClear = ica.getC_Invoice_Cand_ToClear(); assertThat( icToClear + " has wrong C_OrderLine_ID", ol.getC_OrderLine_ID(), equalTo(icToClear.getC_OrderLine_ID())); assertThat( "Sales test driver should have called the update process", icToClear.isToRecompute(), is(false)); assertThat(icToClear.isToClear(), is(true)); if (dataEntryCompleted) { assertThat(ica.getC_Invoice_Candidate_ID(), greaterThan(0)); assertThat( ica.getC_Invoice_Candidate_ID(), equalTo(dataEntry.getC_Invoice_Candidate_ID())); final I_C_Invoice_Candidate newCand = ica.getC_Invoice_Candidate(); assertThat( "Sales test driver should have called the update process", newCand.isToRecompute(), is(false)); assertThat(newCand.isToClear(), is(false)); assertThat(newCand.isProcessed(), is(false)); assertThat(icToClear + " has been marked a processed", icToClear.isProcessed(), is(true)); assertThat(icToClear.getQtyInvoiced(), not(comparesEqualTo(BigDecimal.ZERO))); assertThat(icToClear.getQtyToInvoice(), comparesEqualTo(BigDecimal.ZERO)); sum = sum.add(icToClear.getQtyInvoiced()); } else { assertThat(ica.getC_Invoice_Candidate_ID(), equalTo(0)); assertThat(icToClear + " has wrong 'Processed'", icToClear.isProcessed(), is(false)); assertThat( icToClear + " has wrong 'QtyInvoiced'", icToClear.getQtyInvoiced(), comparesEqualTo(BigDecimal.ZERO)); assertThat( icToClear + " has wrong 'QtyToInvoice'", icToClear.getQtyToInvoice(), not(comparesEqualTo(BigDecimal.ZERO))); sum = sum.add(icToClear.getQtyToInvoice()); } } } if (!paramIsSimulation) { assertThat( "Expecting test config param 'PARAM_ACTUAL_QTY' to match C_FlatRate_DataEntry.ActualQty of " + dataEntry, testConfig.getCustomParamBD(PARAM_BD_ACTUAL_QTY), comparesEqualTo(dataEntry.getActualQty())); assertThat( "Expecting sum of invoice candidates to match C_FlatRate_DataEntry.ActualQty of " + dataEntry, sum, comparesEqualTo(dataEntry.getActualQty())); } }