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