use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class TestFixedAssetLineComputationService method testComputeLastFixedAssetLineWithoutProrata.
@Test
public void testComputeLastFixedAssetLineWithoutProrata() {
FixedAsset fixedAsset = createFixedAsset(FixedAssetRepository.COMPUTATION_METHOD_LINEAR, LocalDate.of(2020, 10, 4), LocalDate.of(2020, 12, 31), 5, 12, createFixedAssetCategoryFromIsProrataTemporis(false), new BigDecimal("500.00"));
FixedAssetLine previousFixedAssetLine = createFixedAssetLine(LocalDate.of(2023, 12, 31), new BigDecimal("100.00"), new BigDecimal("400.00"), new BigDecimal("100.00"));
FixedAssetLine fixedAssetLine = fixedAssetLineComputationService.computePlannedFixedAssetLine(fixedAsset, previousFixedAssetLine);
assertFixedAssetLineEquals(createFixedAssetLine(LocalDate.of(2024, 12, 31), new BigDecimal("100.00"), new BigDecimal("500.00"), new BigDecimal("0.00")), fixedAssetLine);
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetLineMoveServiceImpl method realize.
@Override
@Transactional(rollbackOn = { Exception.class })
public void realize(FixedAssetLine fixedAssetLine) throws AxelorException {
generateMove(fixedAssetLine);
fixedAssetLine.setStatusSelect(FixedAssetLineRepository.STATUS_REALIZED);
FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
BigDecimal residualValue = fixedAsset.getResidualValue();
fixedAsset.setResidualValue(residualValue.subtract(fixedAssetLine.getDepreciation()));
FixedAssetLine plannedFixedAssetLine = fixedAsset.getFixedAssetLineList().stream().filter(line -> line.getStatusSelect() == FixedAssetLineRepository.STATUS_PLANNED).findAny().orElse(null);
if (plannedFixedAssetLine == null && fixedAsset.getDisposalValue().compareTo(BigDecimal.ZERO) == 0) {
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DEPRECIATED);
}
fixedAssetLineRepo.save(fixedAssetLine);
}
use of com.axelor.apps.account.db.FixedAssetLine in project axelor-open-suite by axelor.
the class FixedAssetServiceImpl method disposal.
@Override
@Transactional(rollbackOn = { Exception.class })
public void disposal(LocalDate disposalDate, BigDecimal disposalAmount, FixedAsset fixedAsset) throws AxelorException {
Map<Integer, List<FixedAssetLine>> fixedAssetLineMap = fixedAsset.getFixedAssetLineList().stream().collect(Collectors.groupingBy(FixedAssetLine::getStatusSelect));
List<FixedAssetLine> previousPlannedLineList = fixedAssetLineMap.get(FixedAssetLineRepository.STATUS_PLANNED);
List<FixedAssetLine> previousRealizedLineList = fixedAssetLineMap.get(FixedAssetLineRepository.STATUS_REALIZED);
FixedAssetLine previousPlannedLine = previousPlannedLineList != null && !previousPlannedLineList.isEmpty() ? previousPlannedLineList.get(0) : null;
FixedAssetLine previousRealizedLine = previousRealizedLineList != null && !previousRealizedLineList.isEmpty() ? previousRealizedLineList.get(previousRealizedLineList.size() - 1) : null;
if (previousPlannedLine != null && disposalDate.isAfter(previousPlannedLine.getDepreciationDate())) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.FIXED_ASSET_DISPOSAL_DATE_ERROR_2));
}
if (previousRealizedLine != null && disposalDate.isBefore(previousRealizedLine.getDepreciationDate())) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.FIXED_ASSET_DISPOSAL_DATE_ERROR_1));
}
if (disposalAmount.compareTo(BigDecimal.ZERO) != 0) {
FixedAssetLine depreciationFixedAssetLine = generateProrataDepreciationLine(fixedAsset, disposalDate, previousRealizedLine);
fixedAssetLineMoveService.realize(depreciationFixedAssetLine);
fixedAssetLineMoveService.generateDisposalMove(depreciationFixedAssetLine);
} else {
if (disposalAmount.compareTo(fixedAsset.getResidualValue()) != 0) {
return;
}
}
List<FixedAssetLine> fixedAssetLineList = fixedAsset.getFixedAssetLineList().stream().filter(fixedAssetLine -> fixedAssetLine.getStatusSelect() == FixedAssetLineRepository.STATUS_PLANNED).collect(Collectors.toList());
for (FixedAssetLine fixedAssetLine : fixedAssetLineList) {
fixedAsset.removeFixedAssetLineListItem(fixedAssetLine);
}
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_TRANSFERRED);
fixedAsset.setDisposalDate(disposalDate);
fixedAsset.setDisposalValue(disposalAmount);
fixedAssetRepo.save(fixedAsset);
}
Aggregations