Search in sources :

Example 1 with MoveRepository

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

the class MoveController method deleteMove.

public void deleteMove(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Move move = request.getContext().asType(Move.class);
        MoveRepository moveRepository = Beans.get(MoveRepository.class);
        move = moveRepository.find(move.getId());
        move = moveRepository.find(move.getId());
        this.removeOneMove(move, response);
        if (!move.getStatusSelect().equals(MoveRepository.STATUS_VALIDATED)) {
            response.setView(ActionView.define("Moves").model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException)

Example 2 with MoveRepository

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

the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.

@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
    MoveService moveService = Beans.get(MoveService.class);
    MoveRepository moveRepository = Beans.get(MoveRepository.class);
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    Company company = subrogationRelease.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
    Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
    if (subrogationRelease.getAccountingDate() == null) {
        subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
        boolean isRefund = false;
        if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
            isRefund = true;
        }
        LocalDate date = subrogationRelease.getAccountingDate();
        Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        MoveLine creditMoveLine, debitMoveLine;
        debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        move.addMoveLineListItem(debitMoveLine);
        move.addMoveLineListItem(creditMoveLine);
        move = moveRepository.save(move);
        moveService.getMoveValidateService().validate(move);
        invoice.setSubrogationRelease(subrogationRelease);
        invoice.setSubrogationReleaseMove(move);
        subrogationRelease.addMoveListItem(move);
    }
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) MoveService(com.axelor.apps.account.service.move.MoveService) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AccountConfig(com.axelor.apps.account.db.AccountConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Move(com.axelor.apps.account.db.Move) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

Move (com.axelor.apps.account.db.Move)2 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)2 Account (com.axelor.apps.account.db.Account)1 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 Invoice (com.axelor.apps.account.db.Invoice)1 Journal (com.axelor.apps.account.db.Journal)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 MoveService (com.axelor.apps.account.service.move.MoveService)1 Company (com.axelor.apps.base.db.Company)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1 LocalDate (java.time.LocalDate)1