Program: 58898
Project: 58898
Buggy source:
@Override @Transactional(rollbackOn={AxelorException.class,Exception.class}) public Map<String,Object> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList,Partner contactPartnerIn) throws AxelorException {
  Company invoiceCompany=null;
  Partner invoiceSupplierPartner=null;
  Partner invoiceContactPartner=null;
  PriceList invoicePriceList=null;
  Map<String,Object> mapResult=new HashMap<String,Object>();
  int count=1;
  List<StockMove> stockMoveToInvoiceList=new ArrayList<StockMove>();
  String message="String_Node_Str";
  for (  StockMove stockMove : stockMoveList) {
    if (stockMove.getInvoice() != null) {
      if (stockMove.getInvoice().getStatusSelect() != StockMoveRepository.STATUS_CANCELED) {
        message=String.format(I18n.get(IExceptionMessage.INCOMING_STOCK_MOVE_INVOICE_EXISTS),stockMove.getName());
        if (mapResult.get("String_Node_Str") != null) {
          message=mapResult.get("String_Node_Str") + "String_Node_Str" + message;
        }
        mapResult.put("String_Node_Str",message);
        continue;
      }
    }
    PurchaseOrder purchaseOrder=stockMove.getPurchaseOrder();
    if (count == 1) {
      invoiceCompany=purchaseOrder.getCompany();
      invoiceSupplierPartner=purchaseOrder.getSupplierPartner();
      invoiceContactPartner=purchaseOrder.getContactPartner();
      invoicePriceList=purchaseOrder.getPriceList();
    }
 else {
      if (invoiceCompany != null && !invoiceCompany.equals(purchaseOrder.getCompany())) {
        invoiceCompany=null;
      }
      if (invoiceSupplierPartner != null && !invoiceSupplierPartner.equals(purchaseOrder.getSupplierPartner())) {
        invoiceSupplierPartner=null;
      }
      if (invoiceContactPartner != null && !invoiceContactPartner.equals(purchaseOrder.getContactPartner())) {
        invoiceContactPartner=null;
      }
      if (invoicePriceList != null && !invoicePriceList.equals(purchaseOrder.getPriceList())) {
        invoicePriceList=null;
      }
    }
    stockMoveToInvoiceList.add(stockMove);
    count++;
  }
  if (stockMoveToInvoiceList.isEmpty()) {
    return mapResult;
  }
  StringBuilder fieldErrors=new StringBuilder();
  if (invoiceSupplierPartner == null) {
    fieldErrors.append(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_SUPPLIER_PARTNER);
  }
  if (invoiceCompany == null) {
    if (fieldErrors.length() > 0) {
      fieldErrors.append("String_Node_Str");
    }
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_COMPANY));
  }
  if (fieldErrors.length() > 0) {
    throw new AxelorException(fieldErrors.toString(),IException.CONFIGURATION_ERROR);
  }
  if (invoiceContactPartner == null) {
    if (contactPartnerIn != null) {
      invoiceContactPartner=contactPartnerIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
      mapResult.put("String_Node_Str",invoiceSupplierPartner.getId());
    }
  }
  if (!mapResult.isEmpty()) {
    return mapResult;
  }
  if (invoicePriceList == null) {
    invoicePriceList=invoiceSupplierPartner.getPurchasePriceList();
  }
  String numSeq="String_Node_Str";
  String externalRef="String_Node_Str";
  List<Long> stockMoveIdList=new ArrayList<Long>();
  for (  StockMove stockMoveLocal : stockMoveToInvoiceList) {
    if (!numSeq.isEmpty()) {
      numSeq+="String_Node_Str";
    }
    numSeq+=stockMoveLocal.getPurchaseOrder().getPurchaseOrderSeq();
    if (!externalRef.isEmpty()) {
      externalRef+="String_Node_Str";
    }
    if (stockMoveLocal.getPurchaseOrder().getExternalReference() != null) {
      externalRef+=stockMoveLocal.getPurchaseOrder().getExternalReference();
    }
    stockMoveIdList.add(stockMoveLocal.getId());
  }
  InvoiceGenerator invoiceGenerator=new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE,invoiceCompany,invoiceSupplierPartner,invoiceContactPartner,invoicePriceList,numSeq,externalRef){
    @Override public Invoice generate() throws AxelorException {
      return super.createInvoiceHeader();
    }
  }
;
  Invoice invoice=invoiceGenerator.generate();
  List<InvoiceLine> invoiceLineList=new ArrayList<InvoiceLine>();
  for (  StockMove stockMoveLocal : stockMoveToInvoiceList) {
    invoiceLineList.addAll(this.createInvoiceLines(invoice,stockMoveLocal.getStockMoveLineList()));
  }
  invoiceGenerator.populate(invoice,invoiceLineList);
  if (invoice != null) {
    invoiceRepository.save(invoice);
    JPA.all(StockMove.class).filter("String_Node_Str").bind("String_Node_Str",stockMoveIdList).update("String_Node_Str",invoice);
    mapResult.put("String_Node_Str",invoice.getId());
    return mapResult;
  }
  return mapResult;
}

Fixed version (ground truth):
@Override @Transactional(rollbackOn={AxelorException.class,Exception.class}) public Map<String,Object> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList,Partner contactPartnerIn) throws AxelorException {
  Company invoiceCompany=null;
  Partner invoiceSupplierPartner=null;
  Partner invoiceContactPartner=null;
  PriceList invoicePriceList=null;
  Map<String,Object> mapResult=new HashMap<String,Object>();
  int count=1;
  List<StockMove> stockMoveToInvoiceList=new ArrayList<StockMove>();
  String message="String_Node_Str";
  for (  StockMove stockMove : stockMoveList) {
    if (stockMove.getInvoice() != null) {
      if (stockMove.getInvoice().getStatusSelect() != StockMoveRepository.STATUS_CANCELED) {
        message=String.format(I18n.get(IExceptionMessage.INCOMING_STOCK_MOVE_INVOICE_EXISTS),stockMove.getName());
        if (mapResult.get("String_Node_Str") != null) {
          message=mapResult.get("String_Node_Str") + "String_Node_Str" + message;
        }
        mapResult.put("String_Node_Str",message);
        continue;
      }
    }
    PurchaseOrder purchaseOrder=stockMove.getPurchaseOrder();
    if (count == 1) {
      invoiceCompany=purchaseOrder.getCompany();
      invoiceSupplierPartner=purchaseOrder.getSupplierPartner();
      invoiceContactPartner=purchaseOrder.getContactPartner();
      invoicePriceList=purchaseOrder.getPriceList();
    }
 else {
      if (invoiceCompany != null && !invoiceCompany.equals(purchaseOrder.getCompany())) {
        invoiceCompany=null;
      }
      if (invoiceSupplierPartner != null && !invoiceSupplierPartner.equals(purchaseOrder.getSupplierPartner())) {
        invoiceSupplierPartner=null;
      }
      if (invoiceContactPartner != null && !invoiceContactPartner.equals(purchaseOrder.getContactPartner())) {
        invoiceContactPartner=null;
      }
      if (invoicePriceList != null && !invoicePriceList.equals(purchaseOrder.getPriceList())) {
        invoicePriceList=null;
      }
    }
    stockMoveToInvoiceList.add(stockMove);
    count++;
  }
  if (stockMoveToInvoiceList.isEmpty()) {
    return mapResult;
  }
  StringBuilder fieldErrors=new StringBuilder();
  if (invoiceSupplierPartner == null) {
    fieldErrors.append(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_SUPPLIER_PARTNER);
  }
  if (invoiceCompany == null) {
    if (fieldErrors.length() > 0) {
      fieldErrors.append("String_Node_Str");
    }
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_COMPANY_PO));
  }
  if (fieldErrors.length() > 0) {
    throw new AxelorException(fieldErrors.toString(),IException.CONFIGURATION_ERROR);
  }
  if (invoiceContactPartner == null) {
    if (contactPartnerIn != null) {
      invoiceContactPartner=contactPartnerIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
      mapResult.put("String_Node_Str",invoiceSupplierPartner.getId());
    }
  }
  if (!mapResult.isEmpty()) {
    return mapResult;
  }
  if (invoicePriceList == null) {
    invoicePriceList=invoiceSupplierPartner.getPurchasePriceList();
  }
  String numSeq="String_Node_Str";
  String externalRef="String_Node_Str";
  List<Long> stockMoveIdList=new ArrayList<Long>();
  for (  StockMove stockMoveLocal : stockMoveToInvoiceList) {
    if (!numSeq.isEmpty()) {
      numSeq+="String_Node_Str";
    }
    numSeq+=stockMoveLocal.getPurchaseOrder().getPurchaseOrderSeq();
    if (!externalRef.isEmpty()) {
      externalRef+="String_Node_Str";
    }
    if (stockMoveLocal.getPurchaseOrder().getExternalReference() != null) {
      externalRef+=stockMoveLocal.getPurchaseOrder().getExternalReference();
    }
    stockMoveIdList.add(stockMoveLocal.getId());
  }
  InvoiceGenerator invoiceGenerator=new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE,invoiceCompany,invoiceSupplierPartner,invoiceContactPartner,invoicePriceList,numSeq,externalRef){
    @Override public Invoice generate() throws AxelorException {
      return super.createInvoiceHeader();
    }
  }
;
  Invoice invoice=invoiceGenerator.generate();
  List<InvoiceLine> invoiceLineList=new ArrayList<InvoiceLine>();
  for (  StockMove stockMoveLocal : stockMoveToInvoiceList) {
    invoiceLineList.addAll(this.createInvoiceLines(invoice,stockMoveLocal.getStockMoveLineList()));
  }
  invoiceGenerator.populate(invoice,invoiceLineList);
  if (invoice != null) {
    invoiceRepository.save(invoice);
    JPA.all(StockMove.class).filter("String_Node_Str").bind("String_Node_Str",stockMoveIdList).update("String_Node_Str",invoice);
    mapResult.put("String_Node_Str",invoice.getId());
  }
  return mapResult;
}