Program: 58897
Project: 58897
Buggy source:
@Override @Transactional(rollbackOn={AxelorException.class,Exception.class}) public Map<String,Object> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList,PaymentCondition paymentConditionIn,PaymentMode paymentModeIn,Partner contactPartnerIn) throws AxelorException {
  Currency invoiceCurrency=null;
  Partner invoiceClientPartner=null;
  Company invoiceCompany=null;
  PaymentCondition invoicePaymentCondition=null;
  PaymentMode invoicePaymentMode=null;
  Address invoiceMainInvoicingAddress=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.OUTGOING_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;
      }
    }
    SaleOrder saleOrder=stockMove.getSaleOrder();
    if (count == 1) {
      invoiceCurrency=saleOrder.getCurrency();
      invoiceClientPartner=saleOrder.getClientPartner();
      invoiceCompany=saleOrder.getCompany();
      invoicePaymentCondition=saleOrder.getPaymentCondition();
      invoicePaymentMode=saleOrder.getPaymentMode();
      invoiceMainInvoicingAddress=saleOrder.getMainInvoicingAddress();
      invoiceContactPartner=saleOrder.getContactPartner();
      invoicePriceList=saleOrder.getPriceList();
    }
 else {
      if (invoiceCurrency != null && !invoiceCurrency.equals(saleOrder.getCurrency())) {
        invoiceCurrency=null;
      }
      if (invoiceClientPartner != null && !invoiceClientPartner.equals(saleOrder.getClientPartner())) {
        invoiceClientPartner=null;
      }
      if (invoiceCompany != null && !invoiceCompany.equals(saleOrder.getCompany())) {
        invoiceCompany=null;
      }
      if (invoicePaymentCondition != null && !invoicePaymentCondition.equals(saleOrder.getPaymentCondition())) {
        invoicePaymentCondition=null;
      }
      if (invoicePaymentMode != null && !invoicePaymentMode.equals(saleOrder.getPaymentMode())) {
        invoicePaymentMode=null;
      }
      if (invoiceMainInvoicingAddress != null && !invoiceMainInvoicingAddress.equals(saleOrder.getMainInvoicingAddress())) {
        invoiceMainInvoicingAddress=null;
      }
      if (invoiceContactPartner != null && !invoiceContactPartner.equals(saleOrder.getContactPartner())) {
        invoiceContactPartner=null;
      }
      if (invoicePriceList != null && !invoicePriceList.equals(saleOrder.getPriceList())) {
        invoicePriceList=null;
      }
    }
    stockMoveToInvoiceList.add(stockMove);
    count++;
  }
  if (stockMoveToInvoiceList.isEmpty()) {
    return mapResult;
  }
  StringBuilder fieldErrors=new StringBuilder();
  if (invoiceCurrency == null) {
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_CURRENCY));
  }
  if (invoiceClientPartner == null) {
    if (fieldErrors.length() > 0) {
      fieldErrors.append("String_Node_Str");
    }
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_CLIENT_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 (invoicePaymentCondition == null) {
    if (paymentConditionIn != null) {
      invoicePaymentCondition=paymentConditionIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
    }
  }
  if (invoicePaymentMode == null) {
    if (paymentModeIn != null) {
      invoicePaymentMode=paymentModeIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
    }
  }
  if (invoiceContactPartner == null) {
    if (contactPartnerIn != null) {
      invoiceContactPartner=contactPartnerIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
      mapResult.put("String_Node_Str",invoiceClientPartner.getId());
    }
  }
  if (!mapResult.isEmpty()) {
    return mapResult;
  }
  if (invoiceMainInvoicingAddress == null) {
    invoiceMainInvoicingAddress=invoiceClientPartner.getMainInvoicingAddress();
  }
  if (invoicePriceList == null) {
    invoicePriceList=invoiceClientPartner.getSalePriceList();
  }
  String numSeq="String_Node_Str";
  String internalRef="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.getSaleOrder().getSaleOrderSeq();
    if (!internalRef.isEmpty()) {
      internalRef+="String_Node_Str";
    }
    internalRef+=stockMoveLocal.getStockMoveSeq() + "String_Node_Str" + stockMoveLocal.getSaleOrder().getSaleOrderSeq();
    if (!externalRef.isEmpty()) {
      externalRef+="String_Node_Str";
    }
    if (stockMoveLocal.getSaleOrder().getExternalReference() != null) {
      externalRef+=stockMoveLocal.getSaleOrder().getExternalReference();
    }
    stockMoveIdList.add(stockMoveLocal.getId());
  }
  InvoiceGenerator invoiceGenerator=new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE,invoiceCompany,invoicePaymentCondition,invoicePaymentMode,invoiceMainInvoicingAddress,invoiceClientPartner,invoiceContactPartner,invoiceCurrency,invoicePriceList,numSeq,externalRef){
    @Override public Invoice generate() throws AxelorException {
      return super.createInvoiceHeader();
    }
  }
;
  Invoice invoice=invoiceGenerator.generate();
  invoice.setInternalReference(internalRef);
  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> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList,PaymentCondition paymentConditionIn,PaymentMode paymentModeIn,Partner contactPartnerIn) throws AxelorException {
  Currency invoiceCurrency=null;
  Partner invoiceClientPartner=null;
  Company invoiceCompany=null;
  PaymentCondition invoicePaymentCondition=null;
  PaymentMode invoicePaymentMode=null;
  Address invoiceMainInvoicingAddress=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.OUTGOING_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;
      }
    }
    SaleOrder saleOrder=stockMove.getSaleOrder();
    if (count == 1) {
      invoiceCurrency=saleOrder.getCurrency();
      invoiceClientPartner=saleOrder.getClientPartner();
      invoiceCompany=saleOrder.getCompany();
      invoicePaymentCondition=saleOrder.getPaymentCondition();
      invoicePaymentMode=saleOrder.getPaymentMode();
      invoiceMainInvoicingAddress=saleOrder.getMainInvoicingAddress();
      invoiceContactPartner=saleOrder.getContactPartner();
      invoicePriceList=saleOrder.getPriceList();
    }
 else {
      if (invoiceCurrency != null && !invoiceCurrency.equals(saleOrder.getCurrency())) {
        invoiceCurrency=null;
      }
      if (invoiceClientPartner != null && !invoiceClientPartner.equals(saleOrder.getClientPartner())) {
        invoiceClientPartner=null;
      }
      if (invoiceCompany != null && !invoiceCompany.equals(saleOrder.getCompany())) {
        invoiceCompany=null;
      }
      if (invoicePaymentCondition != null && !invoicePaymentCondition.equals(saleOrder.getPaymentCondition())) {
        invoicePaymentCondition=null;
      }
      if (invoicePaymentMode != null && !invoicePaymentMode.equals(saleOrder.getPaymentMode())) {
        invoicePaymentMode=null;
      }
      if (invoiceMainInvoicingAddress != null && !invoiceMainInvoicingAddress.equals(saleOrder.getMainInvoicingAddress())) {
        invoiceMainInvoicingAddress=null;
      }
      if (invoiceContactPartner != null && !invoiceContactPartner.equals(saleOrder.getContactPartner())) {
        invoiceContactPartner=null;
      }
      if (invoicePriceList != null && !invoicePriceList.equals(saleOrder.getPriceList())) {
        invoicePriceList=null;
      }
    }
    stockMoveToInvoiceList.add(stockMove);
    count++;
  }
  if (stockMoveToInvoiceList.isEmpty()) {
    return mapResult;
  }
  StringBuilder fieldErrors=new StringBuilder();
  if (invoiceCurrency == null) {
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_CURRENCY));
  }
  if (invoiceClientPartner == null) {
    if (fieldErrors.length() > 0) {
      fieldErrors.append("String_Node_Str");
    }
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_CLIENT_PARTNER));
  }
  if (invoiceCompany == null) {
    if (fieldErrors.length() > 0) {
      fieldErrors.append("String_Node_Str");
    }
    fieldErrors.append(I18n.get(IExceptionMessage.STOCK_MOVE_MULTI_INVOICE_COMPANY_SO));
  }
  if (fieldErrors.length() > 0) {
    throw new AxelorException(fieldErrors.toString(),IException.CONFIGURATION_ERROR);
  }
  if (invoicePaymentCondition == null) {
    if (paymentConditionIn != null) {
      invoicePaymentCondition=paymentConditionIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
    }
  }
  if (invoicePaymentMode == null) {
    if (paymentModeIn != null) {
      invoicePaymentMode=paymentModeIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
    }
  }
  if (invoiceContactPartner == null) {
    if (contactPartnerIn != null) {
      invoiceContactPartner=contactPartnerIn;
    }
 else {
      mapResult.put("String_Node_Str",true);
      mapResult.put("String_Node_Str",invoiceClientPartner.getId());
    }
  }
  if (!mapResult.isEmpty()) {
    return mapResult;
  }
  if (invoiceMainInvoicingAddress == null) {
    invoiceMainInvoicingAddress=invoiceClientPartner.getMainInvoicingAddress();
  }
  if (invoicePriceList == null) {
    invoicePriceList=invoiceClientPartner.getSalePriceList();
  }
  String numSeq="String_Node_Str";
  String internalRef="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.getSaleOrder().getSaleOrderSeq();
    if (!internalRef.isEmpty()) {
      internalRef+="String_Node_Str";
    }
    internalRef+=stockMoveLocal.getStockMoveSeq() + "String_Node_Str" + stockMoveLocal.getSaleOrder().getSaleOrderSeq();
    if (!externalRef.isEmpty()) {
      externalRef+="String_Node_Str";
    }
    if (stockMoveLocal.getSaleOrder().getExternalReference() != null) {
      externalRef+=stockMoveLocal.getSaleOrder().getExternalReference();
    }
    stockMoveIdList.add(stockMoveLocal.getId());
  }
  InvoiceGenerator invoiceGenerator=new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE,invoiceCompany,invoicePaymentCondition,invoicePaymentMode,invoiceMainInvoicingAddress,invoiceClientPartner,invoiceContactPartner,invoiceCurrency,invoicePriceList,numSeq,externalRef){
    @Override public Invoice generate() throws AxelorException {
      return super.createInvoiceHeader();
    }
  }
;
  Invoice invoice=invoiceGenerator.generate();
  invoice.setInternalReference(internalRef);
  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;
}