Search in sources :

Example 1 with BlockedSaleOrderException

use of com.axelor.apps.sale.exception.BlockedSaleOrderException in project axelor-open-suite by axelor.

the class SaleOrderWorkflowServiceImpl method finalizeQuotation.

@Override
@Transactional(rollbackOn = { Exception.class }, ignore = { BlockedSaleOrderException.class })
public void finalizeQuotation(SaleOrder saleOrder) throws AxelorException {
    Partner partner = saleOrder.getClientPartner();
    checkSaleOrderBeforeFinalization(saleOrder);
    Blocking blocking = Beans.get(BlockingService.class).getBlocking(partner, saleOrder.getCompany(), BlockingRepository.SALE_BLOCKING);
    if (blocking != null) {
        saleOrder.setBlockedOnCustCreditExceed(true);
        if (!saleOrder.getManualUnblock()) {
            saleOrderRepo.save(saleOrder);
            String reason = blocking.getBlockingReason() != null ? blocking.getBlockingReason().getName() : "";
            throw new BlockedSaleOrderException(partner, I18n.get("Client is sale blocked:") + " " + reason);
        }
    }
    if (saleOrder.getVersionNumber() == 1 && sequenceService.isEmptyOrDraftSequenceNumber(saleOrder.getSaleOrderSeq())) {
        saleOrder.setSaleOrderSeq(this.getSequence(saleOrder.getCompany()));
    }
    saleOrder.setStatusSelect(SaleOrderRepository.STATUS_FINALIZED_QUOTATION);
    if (appSaleService.getAppSale().getPrintingOnSOFinalization()) {
        this.saveSaleOrderPDFAsAttachment(saleOrder);
    }
    saleOrderRepo.save(saleOrder);
}
Also used : Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) BlockedSaleOrderException(com.axelor.apps.sale.exception.BlockedSaleOrderException) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 2 with BlockedSaleOrderException

use of com.axelor.apps.sale.exception.BlockedSaleOrderException in project axelor-open-suite by axelor.

the class AccountingSituationSupplychainServiceImpl method updateCustomerCreditFromSaleOrder.

@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class }, ignore = { BlockedSaleOrderException.class })
public void updateCustomerCreditFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
    if (!appAccountService.getAppAccount().getManageCustomerCredit()) {
        return;
    }
    Partner partner = saleOrder.getClientPartner();
    List<AccountingSituation> accountingSituationList = partner.getAccountingSituationList();
    for (AccountingSituation accountingSituation : accountingSituationList) {
        if (accountingSituation.getCompany().equals(saleOrder.getCompany())) {
            // Update UsedCredit
            accountingSituation = this.computeUsedCredit(accountingSituation);
            if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION) {
                BigDecimal inTaxInvoicedAmount = getInTaxInvoicedAmount(saleOrder);
                BigDecimal usedCredit = accountingSituation.getUsedCredit().add(saleOrder.getInTaxTotal()).subtract(inTaxInvoicedAmount);
                accountingSituation.setUsedCredit(usedCredit);
            }
            boolean usedCreditExceeded = isUsedCreditExceeded(accountingSituation);
            if (usedCreditExceeded) {
                saleOrder.setBlockedOnCustCreditExceed(true);
                if (!saleOrder.getManualUnblock()) {
                    String message = accountingSituation.getCompany().getOrderBloquedMessage();
                    if (Strings.isNullOrEmpty(message)) {
                        message = String.format(I18n.get(IExceptionMessage.SALE_ORDER_CLIENT_PARTNER_EXCEEDED_CREDIT), partner.getFullName(), saleOrder.getSaleOrderSeq());
                    }
                    throw new BlockedSaleOrderException(accountingSituation, message);
                }
            }
        }
    }
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation) BlockedSaleOrderException(com.axelor.apps.sale.exception.BlockedSaleOrderException) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

Partner (com.axelor.apps.base.db.Partner)2 BlockedSaleOrderException (com.axelor.apps.sale.exception.BlockedSaleOrderException)2 Transactional (com.google.inject.persist.Transactional)2 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)1 Blocking (com.axelor.apps.base.db.Blocking)1 BlockingService (com.axelor.apps.base.service.BlockingService)1 BigDecimal (java.math.BigDecimal)1