Program: 59164
Project: 59164
Buggy source:
/** 
 * Méthode permettant de créer un StockMove à partir d'un PurchaseOrder.
 * @param purchaseOrder une commande
 * @throws AxelorException Aucune séquence de StockMove n'a été configurée
 */
public void createStocksMoves(PurchaseOrder purchaseOrder) throws AxelorException {
  if (purchaseOrder.getPurchaseOrderLineList() != null && purchaseOrder.getCompany() != null) {
    Company company=purchaseOrder.getCompany();
    Location startLocation=Location.all().filter("String_Node_Str",purchaseOrder.getSupplierPartner()).fetchOne();
    if (startLocation == null) {
      startLocation=company.getSupplierVirtualLocation();
    }
    if (startLocation == null) {
      throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    StockMove stockMove=stockMoveService.createStockMove(null,company,purchaseOrder.getSupplierPartner(),startLocation,purchaseOrder.getLocation());
    stockMove.setStockMoveLineList(new ArrayList<StockMoveLine>());
    for (    PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
      Product product=purchaseOrderLine.getProduct();
      if (product != null && ((company.getHasInSmForStorableProduct() && product.getProductTypeSelect().equals(IProduct.STORABLE)) || (company.getHasInSmForNonStorableProduct() && !product.getProductTypeSelect().equals(IProduct.STORABLE)))) {
        StockMoveLine stockMoveLine=stockMoveLineService.createStockMoveLine(product,purchaseOrderLine.getQty(),purchaseOrderLine.getUnit(),purchaseOrderLineService.computeDiscount(purchaseOrderLine),stockMove,purchaseOrderLine.getProductVariant(),2);
        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 PurchaseOrder.
 * @param purchaseOrder une commande
 * @throws AxelorException Aucune séquence de StockMove n'a été configurée
 */
public void createStocksMoves(PurchaseOrder purchaseOrder) throws AxelorException {
  if (purchaseOrder.getPurchaseOrderLineList() != null && purchaseOrder.getCompany() != null) {
    Company company=purchaseOrder.getCompany();
    Location startLocation=Location.all().filter("String_Node_Str",purchaseOrder.getSupplierPartner()).fetchOne();
    if (startLocation == null) {
      startLocation=company.getSupplierVirtualLocation();
    }
    if (startLocation == null) {
      throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    StockMove stockMove=stockMoveService.createStockMove(null,company,purchaseOrder.getSupplierPartner(),startLocation,purchaseOrder.getLocation());
    stockMove.setPurchaseOrder(purchaseOrder);
    stockMove.setStockMoveLineList(new ArrayList<StockMoveLine>());
    for (    PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
      Product product=purchaseOrderLine.getProduct();
      if (product != null && ((company.getHasInSmForStorableProduct() && product.getProductTypeSelect().equals(IProduct.STORABLE)) || (company.getHasInSmForNonStorableProduct() && !product.getProductTypeSelect().equals(IProduct.STORABLE)))) {
        StockMoveLine stockMoveLine=stockMoveLineService.createStockMoveLine(product,purchaseOrderLine.getQty(),purchaseOrderLine.getUnit(),purchaseOrderLineService.computeDiscount(purchaseOrderLine),stockMove,purchaseOrderLine.getProductVariant(),2);
        if (stockMoveLine != null) {
          stockMove.getStockMoveLineList().add(stockMoveLine);
        }
      }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
      stockMoveService.validate(stockMove);
    }
  }
}