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);
}
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);
}
}
}
}
}
Aggregations