Search in sources :

Example 1 with AppSupplychain

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

the class ProjectBusinessServiceImpl method generateQuotation.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateQuotation(Project project) throws AxelorException {
    SaleOrder order = Beans.get(SaleOrderCreateService.class).createSaleOrder(project.getCompany());
    Partner clientPartner = project.getClientPartner();
    Partner contactPartner = project.getContactPartner();
    if (contactPartner == null && clientPartner.getContactPartnerSet().size() == 1) {
        contactPartner = clientPartner.getContactPartnerSet().iterator().next();
    }
    Company company = project.getCompany();
    order.setProject(projectRepo.find(project.getId()));
    order.setClientPartner(clientPartner);
    order.setContactPartner(contactPartner);
    order.setCompany(company);
    order.setMainInvoicingAddress(partnerService.getInvoicingAddress(clientPartner));
    order.setMainInvoicingAddressStr(addressService.computeAddressStr(order.getMainInvoicingAddress()));
    order.setDeliveryAddress(partnerService.getDeliveryAddress(clientPartner));
    order.setDeliveryAddressStr(addressService.computeAddressStr(order.getDeliveryAddress()));
    order.setIsNeedingConformityCertificate(clientPartner.getIsNeedingConformityCertificate());
    order.setCompanyBankDetails(Beans.get(AccountingSituationService.class).getCompanySalesBankDetails(company, clientPartner));
    if (project.getCurrency() != null) {
        order.setCurrency(project.getCurrency());
    } else if (clientPartner.getCurrency() != null) {
        order.setCurrency(clientPartner.getCurrency());
    } else {
        order.setCurrency(company.getCurrency());
    }
    if (project.getPriceList() != null) {
        order.setPriceList(project.getPriceList());
    } else {
        order.setPriceList(Beans.get(PartnerPriceListService.class).getDefaultPriceList(clientPartner, PriceListRepository.TYPE_SALE));
    }
    if (order.getPriceList() != null) {
        order.setHideDiscount(order.getPriceList().getHideDiscount());
    }
    if (clientPartner.getPaymentCondition() != null) {
        order.setPaymentCondition(clientPartner.getPaymentCondition());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentCondition(company.getAccountConfig().getDefPaymentCondition());
        }
    }
    if (clientPartner.getInPaymentMode() != null) {
        order.setPaymentMode(clientPartner.getInPaymentMode());
    } else {
        if (company != null && company.getAccountConfig() != null) {
            order.setPaymentMode(company.getAccountConfig().getInPaymentMode());
        }
    }
    AppSupplychain appSupplychain = Beans.get(AppSupplychainService.class).getAppSupplychain();
    if (appSupplychain != null) {
        order.setShipmentMode(clientPartner.getShipmentMode());
        order.setFreightCarrierMode(clientPartner.getFreightCarrierMode());
        if (clientPartner.getFreightCarrierMode() != null) {
            order.setCarrierPartner(clientPartner.getFreightCarrierMode().getCarrierPartner());
        }
        Boolean interco = appSupplychain.getIntercoFromSale() && !order.getCreatedByInterco() && clientPartner != null && Beans.get(CompanyRepository.class).all().filter("self.partner = ?", clientPartner).fetchOne() != null;
        order.setInterco(interco);
        // Automatic invoiced and delivered partners set in case of partner delegations
        if (appSupplychain.getActivatePartnerRelations()) {
            Beans.get(SaleOrderSupplychainService.class).setDefaultInvoicedAndDeliveredPartnersAndAddresses(order);
        }
    }
    return Beans.get(SaleOrderRepository.class).save(order);
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Transactional(com.google.inject.persist.Transactional)

Example 2 with AppSupplychain

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

the class StockMoveServiceSupplychainImpl method verifyProductStock.

@Override
public void verifyProductStock(StockMove stockMove) throws AxelorException {
    AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
    if (stockMove.getAvailabilityRequest() && stockMove.getStockMoveLineList() != null && appSupplychain.getIsVerifyProductStock() && stockMove.getFromStockLocation() != null) {
        StringJoiner notAvailableProducts = new StringJoiner(",");
        int counter = 1;
        for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
            boolean isAvailableProduct = stockMoveLineServiceSupplychain.isAvailableProduct(stockMove, stockMoveLine);
            if (!isAvailableProduct && counter <= 10) {
                notAvailableProducts.add(stockMoveLine.getProduct().getFullName());
                counter++;
            }
        }
        if (!Strings.isNullOrEmpty(notAvailableProducts.toString())) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.STOCK_MOVE_VERIFY_PRODUCT_STOCK_ERROR), notAvailableProducts.toString()));
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StringJoiner(java.util.StringJoiner)

Example 3 with AppSupplychain

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

the class StockMoveServiceSupplychainImpl method realize.

@Override
@Transactional(rollbackOn = { Exception.class })
public String realize(StockMove stockMove, boolean check) throws AxelorException {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return super.realize(stockMove, check);
    }
    LOG.debug("RĂ©alisation du mouvement de stock : {} ", stockMove.getStockMoveSeq());
    String newStockSeq = super.realize(stockMove, check);
    AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        updateSaleOrderLinesDeliveryState(stockMove, !stockMove.getIsReversion());
        // Update linked saleOrder delivery state depending on BackOrder's existence
        SaleOrder saleOrder = saleOrderRepo.find(stockMove.getOriginId());
        if (newStockSeq != null) {
            saleOrder.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
        } else {
            Beans.get(SaleOrderStockService.class).updateDeliveryState(saleOrder);
            if (appSupplychain.getTerminateSaleOrderOnDelivery()) {
                terminateOrConfirmSaleOrderStatus(saleOrder);
            }
        }
        Beans.get(SaleOrderRepository.class).save(saleOrder);
    } else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        updatePurchaseOrderLines(stockMove, !stockMove.getIsReversion());
        // Update linked purchaseOrder receipt state depending on BackOrder's existence
        PurchaseOrder purchaseOrder = purchaseOrderRepo.find(stockMove.getOriginId());
        if (newStockSeq != null) {
            purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
        } else {
            Beans.get(PurchaseOrderStockService.class).updateReceiptState(purchaseOrder);
            if (appSupplychain.getTerminatePurchaseOrderOnReceipt()) {
                finishOrValidatePurchaseOrderStatus(purchaseOrder);
            }
        }
        Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
    }
    if (appSupplyChainService.getAppSupplychain().getManageStockReservation()) {
        Beans.get(ReservedQtyService.class).updateReservedQuantity(stockMove, StockMoveRepository.STATUS_REALIZED);
    }
    detachNonDeliveredStockMoveLines(stockMove);
    List<Long> trackingNumberIds = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getTrackingNumber).filter(Objects::nonNull).map(TrackingNumber::getId).filter(Objects::nonNull).collect(Collectors.toList());
    if (CollectionUtils.isNotEmpty(trackingNumberIds)) {
        Query update = JPA.em().createQuery("UPDATE FixedAsset self SET self.stockLocation = :stockLocation WHERE self.trackingNumber.id IN (:trackingNumber)");
        update.setParameter("stockLocation", stockMove.getToStockLocation());
        update.setParameter("trackingNumber", trackingNumberIds);
        update.executeUpdate();
    }
    return newStockSeq;
}
Also used : AppSupplychain(com.axelor.apps.base.db.AppSupplychain) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Query(javax.persistence.Query) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Aggregations

AppSupplychain (com.axelor.apps.base.db.AppSupplychain)3 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 Transactional (com.google.inject.persist.Transactional)2 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 SaleOrderCreateService (com.axelor.apps.sale.service.saleorder.SaleOrderCreateService)1 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)1 SaleOrderSupplychainService (com.axelor.apps.supplychain.service.SaleOrderSupplychainService)1 AppSupplychainService (com.axelor.apps.supplychain.service.app.AppSupplychainService)1 AxelorException (com.axelor.exception.AxelorException)1 StringJoiner (java.util.StringJoiner)1 Query (javax.persistence.Query)1