Search in sources :

Example 16 with FixedAssetLine

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);
}
Also used : FixedAssetTestTool.createFixedAssetLine(com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAssetLine) FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) FixedAssetTestTool.createFixedAsset(com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAsset) FixedAsset(com.axelor.apps.account.db.FixedAsset) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 17 with 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);
}
Also used : FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) FixedAsset(com.axelor.apps.account.db.FixedAsset) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 18 with 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);
}
Also used : AccountConfig(com.axelor.apps.account.db.AccountConfig) Inject(com.google.inject.Inject) FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) MoveLine(com.axelor.apps.account.db.MoveLine) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) I18n(com.axelor.i18n.I18n) FixedAssetRepository(com.axelor.apps.account.db.repo.FixedAssetRepository) RoundingMode(java.math.RoundingMode) MoveLineService(com.axelor.apps.account.service.move.MoveLineService) JPA(com.axelor.db.JPA) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) AnalyticDistributionTemplate(com.axelor.apps.account.db.AnalyticDistributionTemplate) FixedAssetLineRepository(com.axelor.apps.account.db.repo.FixedAssetLineRepository) FixedAsset(com.axelor.apps.account.db.FixedAsset) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) FixedAssetLine(com.axelor.apps.account.db.FixedAssetLine) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(com.google.inject.persist.Transactional)

Aggregations

FixedAssetLine (com.axelor.apps.account.db.FixedAssetLine)18 BigDecimal (java.math.BigDecimal)13 FixedAsset (com.axelor.apps.account.db.FixedAsset)12 FixedAssetTestTool.createFixedAsset (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAsset)10 FixedAssetTestTool.createFixedAssetLine (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAssetLine)10 Test (org.junit.Test)10 LocalDate (java.time.LocalDate)3 FixedAssetLineRepository (com.axelor.apps.account.db.repo.FixedAssetLineRepository)2 Transactional (com.google.inject.persist.Transactional)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 AnalyticDistributionTemplate (com.axelor.apps.account.db.AnalyticDistributionTemplate)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 FixedAssetRepository (com.axelor.apps.account.db.repo.FixedAssetRepository)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 FixedAssetLineMoveService (com.axelor.apps.account.service.fixedasset.FixedAssetLineMoveService)1 MoveLineService (com.axelor.apps.account.service.move.MoveLineService)1 JPA (com.axelor.db.JPA)1