Search in sources :

Example 1 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetLineMoveServiceImpl method generateDisposalMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateDisposalMove(FixedAssetLine fixedAssetLine) throws AxelorException {
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    Journal journal = fixedAsset.getJournal();
    Company company = fixedAsset.getCompany();
    Partner partner = fixedAsset.getPartner();
    LocalDate date = fixedAssetLine.getDepreciationDate();
    // Creating move
    Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
    if (move != null) {
        List<MoveLine> moveLines = new ArrayList<MoveLine>();
        String origin = fixedAsset.getReference();
        Account chargeAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
        Account depreciationAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
        Account purchaseAccount = fixedAsset.getPurchaseAccount();
        BigDecimal chargeAmount = fixedAssetLine.getResidualValue();
        BigDecimal cumulativeDepreciationAmount = fixedAssetLine.getCumulativeDepreciation();
        // Creating accounting debit move line for charge account
        MoveLine chargeAccountDebitMoveLine = new MoveLine(move, partner, chargeAccount, date, null, 1, chargeAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(chargeAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), chargeAccountDebitMoveLine);
        // Creating accounting debit move line for deprecation account
        MoveLine deprecationAccountDebitMoveLine = new MoveLine(move, partner, depreciationAccount, date, null, 1, cumulativeDepreciationAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(deprecationAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), deprecationAccountDebitMoveLine);
        // Creating accounting credit move line
        MoveLine creditMoveLine = new MoveLine(move, partner, purchaseAccount, date, null, 2, BigDecimal.ZERO, fixedAsset.getGrossValue(), fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(creditMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
        move.getMoveLineList().addAll(moveLines);
    }
    moveRepo.save(move);
    fixedAsset.setDisposalMove(move);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) FixedAsset(com.axelor.apps.account.db.FixedAsset) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 2 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetServiceImpl method createFixedAssets.

@Override
@Transactional(rollbackOn = { Exception.class })
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
    List<FixedAsset> fixedAssetList = new ArrayList<>();
    if (invoice == null || CollectionUtils.isEmpty(invoice.getInvoiceLineList())) {
        return fixedAssetList;
    }
    AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany());
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        if (accountConfig.getFixedAssetCatReqOnInvoice() && invoiceLine.getFixedAssets() && invoiceLine.getFixedAssetCategory() == null) {
            throw new AxelorException(invoiceLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_LINE_ERROR_FIXED_ASSET_CATEGORY), invoiceLine.getProductName());
        }
        if (!invoiceLine.getFixedAssets() || invoiceLine.getFixedAssetCategory() == null) {
            continue;
        }
        FixedAsset fixedAsset = new FixedAsset();
        fixedAsset.setFixedAssetCategory(invoiceLine.getFixedAssetCategory());
        if (fixedAsset.getFixedAssetCategory().getIsValidateFixedAsset()) {
            fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_VALIDATED);
        } else {
            fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DRAFT);
        }
        fixedAsset.setAcquisitionDate(invoice.getInvoiceDate());
        fixedAsset.setFirstDepreciationDate(invoice.getInvoiceDate());
        fixedAsset.setReference(invoice.getInvoiceId());
        fixedAsset.setName(invoiceLine.getProductName() + " (" + invoiceLine.getQty() + ")");
        fixedAsset.setCompany(fixedAsset.getFixedAssetCategory().getCompany());
        fixedAsset.setJournal(fixedAsset.getFixedAssetCategory().getJournal());
        fixedAsset.setComputationMethodSelect(fixedAsset.getFixedAssetCategory().getComputationMethodSelect());
        fixedAsset.setDegressiveCoef(fixedAsset.getFixedAssetCategory().getDegressiveCoef());
        fixedAsset.setNumberOfDepreciation(fixedAsset.getFixedAssetCategory().getNumberOfDepreciation());
        fixedAsset.setPeriodicityInMonth(fixedAsset.getFixedAssetCategory().getPeriodicityInMonth());
        fixedAsset.setDurationInMonth(fixedAsset.getFixedAssetCategory().getDurationInMonth());
        fixedAsset.setGrossValue(invoiceLine.getCompanyExTaxTotal());
        fixedAsset.setPartner(invoice.getPartner());
        fixedAsset.setPurchaseAccount(invoiceLine.getAccount());
        fixedAsset.setInvoiceLine(invoiceLine);
        this.generateAndComputeLines(fixedAsset);
        fixedAssetList.add(fixedAssetRepo.save(fixedAsset));
    }
    return fixedAssetList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) FixedAsset(com.axelor.apps.account.db.FixedAsset) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 3 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class FixedAssetTestTool method createFixedAsset.

public static FixedAsset createFixedAsset(String computationMethodSelect, BigDecimal degressiveCoef, LocalDate acquisitionDate, LocalDate firstDepreciationDate, int numberOfDepreciation, int periodicityInMonth, FixedAssetCategory fixedAssetCategory, BigDecimal grossValue) {
    FixedAsset fixedAsset = new FixedAsset();
    fixedAsset.setComputationMethodSelect(computationMethodSelect);
    fixedAsset.setDegressiveCoef(degressiveCoef);
    fixedAsset.setFirstDepreciationDate(firstDepreciationDate);
    fixedAsset.setAcquisitionDate(acquisitionDate);
    fixedAsset.setNumberOfDepreciation(numberOfDepreciation);
    fixedAsset.setPeriodicityInMonth(periodicityInMonth);
    fixedAsset.setDurationInMonth(numberOfDepreciation * periodicityInMonth);
    fixedAsset.setFixedAssetCategory(fixedAssetCategory);
    fixedAsset.setGrossValue(grossValue);
    return fixedAsset;
}
Also used : FixedAsset(com.axelor.apps.account.db.FixedAsset)

Example 4 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class TestFixedAssetLineComputationService method testComputeLastFixedAssetLineWithProrata.

@Test
public void testComputeLastFixedAssetLineWithProrata() {
    FixedAsset fixedAsset = createFixedAsset(FixedAssetRepository.COMPUTATION_METHOD_LINEAR, LocalDate.of(2020, 10, 4), LocalDate.of(2020, 12, 31), 5, 12, createFixedAssetCategoryFromIsProrataTemporis(true), new BigDecimal("500.00"));
    FixedAssetLine previousFixedAssetLine = createFixedAssetLine(LocalDate.of(2024, 12, 31), new BigDecimal("100.00"), new BigDecimal("423.89"), new BigDecimal("76.11"));
    FixedAssetLine fixedAssetLine = fixedAssetLineComputationService.computePlannedFixedAssetLine(fixedAsset, previousFixedAssetLine);
    assertFixedAssetLineEquals(createFixedAssetLine(LocalDate.of(2025, 10, 3), new BigDecimal("76.11"), 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 5 with FixedAsset

use of com.axelor.apps.account.db.FixedAsset in project axelor-open-suite by axelor.

the class TestFixedAssetLineComputationService method testComputeFirstDegressiveAssetLine.

@Test
public void testComputeFirstDegressiveAssetLine() {
    FixedAsset fixedAsset = createFixedAsset(FixedAssetRepository.COMPUTATION_METHOD_DEGRESSIVE, new BigDecimal("1.75"), LocalDate.of(2020, 3, 31), LocalDate.of(2020, 12, 31), 5, 12, createFixedAssetCategoryFromIsProrataTemporis(true, false), new BigDecimal("20000.00"));
    FixedAssetLine fixedAssetLine = fixedAssetLineComputationService.computeInitialPlannedFixedAssetLine(fixedAsset);
    assertFixedAssetLineEquals(createFixedAssetLine(LocalDate.of(2020, 12, 31), new BigDecimal("5250.00"), new BigDecimal("5250.00"), new BigDecimal("14750.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)

Aggregations

FixedAsset (com.axelor.apps.account.db.FixedAsset)65 FixedAssetTestTool.createFixedAsset (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAsset)52 BigDecimal (java.math.BigDecimal)52 Test (org.junit.Test)47 FixedAssetLine (com.axelor.apps.account.db.FixedAssetLine)12 FixedAssetTestTool.createFixedAssetLine (com.axelor.apps.account.service.fixedasset.FixedAssetTestTool.createFixedAssetLine)10 Transactional (com.google.inject.persist.Transactional)6 AxelorException (com.axelor.exception.AxelorException)5 ArrayList (java.util.ArrayList)5 LocalDate (java.time.LocalDate)4 MoveLine (com.axelor.apps.account.db.MoveLine)3 FixedAssetRepository (com.axelor.apps.account.db.repo.FixedAssetRepository)3 FixedAssetService (com.axelor.apps.account.service.fixedasset.FixedAssetService)3 Account (com.axelor.apps.account.db.Account)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 Journal (com.axelor.apps.account.db.Journal)2 Move (com.axelor.apps.account.db.Move)2 Company (com.axelor.apps.base.db.Company)2 Partner (com.axelor.apps.base.db.Partner)2