Search in sources :

Example 1 with Blocking

use of com.axelor.apps.base.db.Blocking 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 Blocking

use of com.axelor.apps.base.db.Blocking in project axelor-open-suite by axelor.

the class SaleOrderLineController method supplierPartnerDefault.

/**
 * Called from sale order line form, on product change and on sale supply select change
 *
 * @param request
 * @param response
 */
public void supplierPartnerDefault(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_PURCHASE) {
        return;
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (saleOrder == null) {
        Context parentContext = request.getContext().getParent();
        if (parentContext == null) {
            return;
        }
        saleOrder = parentContext.asType(SaleOrder.class);
    }
    if (saleOrder == null) {
        return;
    }
    Partner supplierPartner = null;
    if (saleOrderLine.getProduct() != null) {
        supplierPartner = saleOrderLine.getProduct().getDefaultSupplierPartner();
    }
    if (supplierPartner != null) {
        Blocking blocking = Beans.get(BlockingService.class).getBlocking(supplierPartner, saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
        if (blocking != null) {
            supplierPartner = null;
        }
    }
    response.setValue("supplierPartner", supplierPartner);
}
Also used : Context(com.axelor.rpc.Context) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner)

Example 3 with Blocking

use of com.axelor.apps.base.db.Blocking in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method requestPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_REQUESTED);
    Partner partner = purchaseOrder.getSupplierPartner();
    Company company = purchaseOrder.getCompany();
    Blocking blocking = Beans.get(BlockingService.class).getBlocking(partner, company, BlockingRepository.PURCHASE_BLOCKING);
    if (blocking != null) {
        String reason = blocking.getBlockingReason() != null ? blocking.getBlockingReason().getName() : "";
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SUPPLIER_BLOCKED) + " " + reason, partner);
    }
    if (purchaseOrder.getVersionNumber() == 1 && sequenceService.isEmptyOrDraftSequenceNumber(purchaseOrder.getPurchaseOrderSeq())) {
        purchaseOrder.setPurchaseOrderSeq(this.getSequence(purchaseOrder.getCompany()));
    }
    purchaseOrderRepo.save(purchaseOrder);
    if (appPurchaseService.getAppPurchase().getManagePurchaseOrderVersion()) {
        this.savePurchaseOrderPDFAsAttachment(purchaseOrder);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 4 with Blocking

use of com.axelor.apps.base.db.Blocking in project axelor-open-suite by axelor.

the class PurchaseOrderSupplierService method generateSuppliersRequests.

@Transactional
public void generateSuppliersRequests(PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder) {
    if (purchaseOrder == null) {
        return;
    }
    Product product = purchaseOrderLine.getProduct();
    Company company = purchaseOrder.getCompany();
    if (Beans.get(AppPurchaseService.class).getAppPurchase().getManageSupplierCatalog() && product != null && product.getSupplierCatalogList() != null) {
        for (SupplierCatalog supplierCatalog : product.getSupplierCatalogList()) {
            Partner supplierPartner = supplierCatalog.getSupplierPartner();
            Blocking blocking = Beans.get(BlockingService.class).getBlocking(supplierPartner, company, BlockingRepository.PURCHASE_BLOCKING);
            if (blocking == null) {
                purchaseOrderLine.addPurchaseOrderSupplierLineListItem(purchaseOrderSupplierLineService.create(supplierPartner, supplierCatalog.getPrice()));
            }
        }
    }
    Beans.get(PurchaseOrderLineRepository.class).save(purchaseOrderLine);
}
Also used : PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Company(com.axelor.apps.base.db.Company) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) Product(com.axelor.apps.base.db.Product) SupplierCatalog(com.axelor.apps.purchase.db.SupplierCatalog) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

Blocking (com.axelor.apps.base.db.Blocking)4 Partner (com.axelor.apps.base.db.Partner)4 BlockingService (com.axelor.apps.base.service.BlockingService)4 Transactional (com.google.inject.persist.Transactional)3 Company (com.axelor.apps.base.db.Company)2 Product (com.axelor.apps.base.db.Product)1 SupplierCatalog (com.axelor.apps.purchase.db.SupplierCatalog)1 PurchaseOrderLineRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 BlockedSaleOrderException (com.axelor.apps.sale.exception.BlockedSaleOrderException)1 AxelorException (com.axelor.exception.AxelorException)1 Context (com.axelor.rpc.Context)1