Program: 59165
Project: 59165
Buggy source:
/** 
 * Méthode permettant de créer un StockMove à partir d'un SalesOrder.
 * @param salesOrder l'objet salesOrder
 * @throws AxelorException Aucune séquence de StockMove (Livraison) n'a été configurée
 */
public void createStocksMovesFromSalesOrder(SalesOrder salesOrder) throws AxelorException {
  if (salesOrder.getSalesOrderLineList() != null && salesOrder.getCompany() != null) {
    Company company=salesOrder.getCompany();
    Location toLocation=Location.all().filter("String_Node_Str",company,ILocation.EXTERNAL).fetchOne();
    if (toLocation == null) {
      toLocation=company.getCustomerVirtualLocation();
    }
    if (toLocation == null) {
      throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    StockMove stockMove=stockMoveService.createStockMove(salesOrder.getDeliveryAddress(),company,salesOrder.getClientPartner(),salesOrder.getLocation(),toLocation);
    stockMove.setStockMoveLineList(new ArrayList<StockMoveLine>());
    for (    SalesOrderLine salesOrderLine : salesOrder.getSalesOrderLineList()) {
      Product product=salesOrderLine.getProduct();
      if (product != null && ((company.getHasOutSmForStorableProduct() && product.getProductTypeSelect().equals(IProduct.STORABLE)) || (company.getHasOutSmForNonStorableProduct() && !product.getProductTypeSelect().equals(IProduct.STORABLE)))) {
        StockMoveLine stockMoveLine=stockMoveLineService.createStockMoveLine(product,salesOrderLine.getQty(),salesOrderLine.getUnit(),salesOrderLineService.computeDiscount(salesOrderLine),stockMove,salesOrderLine.getProductVariant(),1);
        if (stockMoveLine != null) {
          stockMove.getStockMoveLineList().add(stockMoveLine);
        }
      }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
      stockMoveService.validate(stockMove);
    }
  }
}

Fixed version (ground truth):
/** 
 * Méthode permettant de créer un StockMove à partir d'un SalesOrder.
 * @param salesOrder l'objet salesOrder
 * @throws AxelorException Aucune séquence de StockMove (Livraison) n'a été configurée
 */
public void createStocksMovesFromSalesOrder(SalesOrder salesOrder) throws AxelorException {
  if (salesOrder.getSalesOrderLineList() != null && salesOrder.getCompany() != null) {
    Company company=salesOrder.getCompany();
    Location toLocation=Location.all().filter("String_Node_Str",company,ILocation.EXTERNAL).fetchOne();
    if (toLocation == null) {
      toLocation=company.getCustomerVirtualLocation();
    }
    if (toLocation == null) {
      throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    StockMove stockMove=stockMoveService.createStockMove(salesOrder.getDeliveryAddress(),company,salesOrder.getClientPartner(),salesOrder.getLocation(),toLocation);
    stockMove.setSalesOrder(salesOrder);
    stockMove.setStockMoveLineList(new ArrayList<StockMoveLine>());
    for (    SalesOrderLine salesOrderLine : salesOrder.getSalesOrderLineList()) {
      Product product=salesOrderLine.getProduct();
      if (product != null && ((company.getHasOutSmForStorableProduct() && product.getProductTypeSelect().equals(IProduct.STORABLE)) || (company.getHasOutSmForNonStorableProduct() && !product.getProductTypeSelect().equals(IProduct.STORABLE)))) {
        StockMoveLine stockMoveLine=stockMoveLineService.createStockMoveLine(product,salesOrderLine.getQty(),salesOrderLine.getUnit(),salesOrderLineService.computeDiscount(salesOrderLine),stockMove,salesOrderLine.getProductVariant(),1);
        if (stockMoveLine != null) {
          stockMove.getStockMoveLineList().add(stockMoveLine);
        }
      }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
      stockMoveService.validate(stockMove);
    }
  }
}