Search in sources :

Example 6 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method isStockMoveProduct.

public boolean isStockMoveProduct(PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder) throws AxelorException {
    Company company = purchaseOrder.getCompany();
    SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
    Product product = purchaseOrderLine.getProduct();
    return (product != null && ((ProductRepository.PRODUCT_TYPE_SERVICE.equals(product.getProductTypeSelect()) && supplyChainConfig.getHasInSmForNonStorableProduct() && !product.getIsShippingCostsProduct()) || (ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect()) && supplyChainConfig.getHasInSmForStorableProduct())));
}
Also used : Company(com.axelor.apps.base.db.Company) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Product(com.axelor.apps.base.db.Product) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig)

Example 7 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createStockMove.

protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    Partner supplierPartner = purchaseOrder.getSupplierPartner();
    Company company = purchaseOrder.getCompany();
    Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
    StockLocation startLocation = getStartStockLocation(purchaseOrder);
    StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    stockMove.setOriginId(purchaseOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    stockMove.setTradingName(purchaseOrder.getTradingName());
    stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    qualityStockMove.setOriginId(purchaseOrder.getId());
    qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    qualityStockMove.setTradingName(purchaseOrder.getTradingName());
    qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
    } else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
    }
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
        if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
            this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
        }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(stockMove);
        stockMoveIdList.add(stockMove.getId());
    }
    if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(qualityStockMove);
        stockMoveIdList.add(qualityStockMove.getId());
    }
    return stockMoveIdList;
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Address(com.axelor.apps.base.db.Address) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) PartnerService(com.axelor.apps.base.service.PartnerService) BigDecimal(java.math.BigDecimal) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Partner(com.axelor.apps.base.db.Partner)

Example 8 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method setReservationDateTime.

/**
 * Fill reservation date time in stock move lines with sale order following supplychain
 * configuration.
 *
 * @param stockMove
 * @param saleOrder
 */
protected void setReservationDateTime(StockMove stockMove, SaleOrder saleOrder) throws AxelorException {
    SupplyChainConfig supplyChainConfig = supplyChainConfigService.getSupplyChainConfig(saleOrder.getCompany());
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        stockMoveLineList = new ArrayList<>();
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        LocalDateTime reservationDateTime;
        switch(supplyChainConfig.getSaleOrderReservationDateSelect()) {
            case SupplyChainConfigRepository.SALE_ORDER_CONFIRMATION_DATE:
                reservationDateTime = saleOrder.getConfirmationDateTime();
                break;
            case SupplyChainConfigRepository.SALE_ORDER_SHIPPING_DATE:
                SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
                if (saleOrderLine == null || saleOrderLine.getEstimatedDelivDate() == null) {
                    reservationDateTime = null;
                } else {
                    reservationDateTime = saleOrderLine.getEstimatedDelivDate().atStartOfDay();
                }
                break;
            default:
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RESERVATION_SALE_ORDER_DATE_CONFIG_INCORRECT_VALUE));
        }
        if (reservationDateTime == null) {
            reservationDateTime = Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime();
        }
        stockMoveLine.setReservationDateTime(reservationDateTime);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 9 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method isStockMoveProduct.

@Override
public boolean isStockMoveProduct(SaleOrderLine saleOrderLine, SaleOrder saleOrder) throws AxelorException {
    Company company = saleOrder.getCompany();
    SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
    Product product = saleOrderLine.getProduct();
    return (product != null && ((ProductRepository.PRODUCT_TYPE_SERVICE.equals(product.getProductTypeSelect()) && supplyChainConfig.getHasOutSmForNonStorableProduct() && !product.getIsShippingCostsProduct()) || (ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect()) && supplyChainConfig.getHasOutSmForStorableProduct())));
}
Also used : Company(com.axelor.apps.base.db.Company) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Product(com.axelor.apps.base.db.Product) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig)

Example 10 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class AppSupplychainServiceImpl method generateSupplychainConfigurations.

@Override
@Transactional
public void generateSupplychainConfigurations() {
    List<Company> companies = companyRepo.all().filter("self.supplyChainConfig is null").fetch();
    for (Company company : companies) {
        SupplyChainConfig supplyChainConfig = new SupplyChainConfig();
        supplyChainConfig.setCompany(company);
        supplyChainConfigRepo.save(supplyChainConfig);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Transactional(com.google.inject.persist.Transactional)

Aggregations

SupplyChainConfig (com.axelor.apps.supplychain.db.SupplyChainConfig)11 Company (com.axelor.apps.base.db.Company)8 SupplyChainConfigService (com.axelor.apps.supplychain.service.config.SupplyChainConfigService)7 StockMove (com.axelor.apps.stock.db.StockMove)5 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)3 Product (com.axelor.apps.base.db.Product)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 AppSupplychainService (com.axelor.apps.supplychain.service.app.AppSupplychainService)2 AxelorException (com.axelor.exception.AxelorException)2 BigDecimal (java.math.BigDecimal)2 Invoice (com.axelor.apps.account.db.Invoice)1 Address (com.axelor.apps.base.db.Address)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1 StockMoveInvoiceService (com.axelor.apps.supplychain.service.StockMoveInvoiceService)1