/** * Save any edits. * * <p>This links the adjustment to the <em>act.tillBalance</em> and forces a recalculation, if one * is present. * * @return {@code true} if the save was successful */ @Override protected boolean doSave() { boolean result; if (currentBalance != null && !TillBalanceStatus.CLEARED.equals(currentBalance.getStatus())) { ActBean bean = new ActBean(currentBalance); bean.addNodeRelationship("items", (Act) getObject()); bean.save(); result = super.doSave(); if (result) { // need to update the balance after the adjustment is saved TillRules rules = ServiceHelper.getBean(TillRules.class); rules.updateBalance(currentBalance); } } else { result = super.doSave(); } return result; }
/** * Validates the object. * * @param validator the validator * @return {@code true} if the object and its descendants are valid otherwise {@code false} */ @Override protected boolean doValidation(Validator validator) { boolean result = super.doValidation(validator); if (result) { FinancialAct balance = (FinancialAct) getParent(); if (balance != null) { currentBalance = IMObjectHelper.reload(balance); // make sure we have the latest instance if (currentBalance == null) { ErrorDialog.show( Messages.format("imobject.noexist", DescriptorHelper.getDisplayName(balance))); result = false; } else if (TillBalanceStatus.CLEARED.equals(currentBalance.getStatus())) { ErrorDialog.show(Messages.get("till.adjustment.error.clearedBalance")); result = false; } } } return result; }