Program: 58790
Project: 58790
Buggy source:
protected Invoice createInvoiceHeader() throws AxelorException {
  Invoice invoice=new Invoice();
  invoice.setOperationTypeSelect(operationType);
  if (partner == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_2),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPartner(partner);
  if (paymentCondition == null) {
    paymentCondition=partner.getPaymentCondition();
  }
  if (paymentCondition == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_3),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPaymentCondition(paymentCondition);
  if (paymentMode == null) {
    paymentMode=partner.getPaymentMode();
  }
  if (paymentMode == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_4),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPaymentMode(paymentMode);
  if (mainInvoicingAddress == null) {
    mainInvoicingAddress=Beans.get(PartnerService.class).getInvoicingAddress(partner);
  }
  if (mainInvoicingAddress == null && partner.getIsCustomer()) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_5),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setAddress(mainInvoicingAddress);
  invoice.setContactPartner(contactPartner);
  if (currency == null) {
    currency=partner.getCurrency();
  }
  if (currency == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_6),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setCurrency(currency);
  invoice.setCompany(company);
  invoice.setPartnerAccount(Beans.get(AccountCustomerService.class).getPartnerAccount(partner,company,operationType == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || operationType == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND));
  invoice.setJournal(journalService.getJournal(invoice));
  invoice.setStatusSelect(InvoiceRepository.STATUS_DRAFT);
  if (priceList == null) {
    if (InvoiceToolService.isPurchase(invoice)) {
      priceList=partner.getPurchasePriceList();
    }
 else {
      priceList=partner.getSalePriceList();
    }
  }
  invoice.setPriceList(priceList);
  invoice.setInternalReference(internalReference);
  invoice.setExternalReference(externalReference);
  invoice.setInAti(inAti);
  initCollections(invoice);
  return invoice;
}

Fixed version (ground truth):
protected Invoice createInvoiceHeader() throws AxelorException {
  Invoice invoice=new Invoice();
  invoice.setOperationTypeSelect(operationType);
  if (partner == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_2),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPartner(partner);
  if (paymentCondition == null) {
    paymentCondition=partner.getPaymentCondition();
  }
  if (paymentCondition == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_3),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPaymentCondition(paymentCondition);
  if (paymentMode == null) {
    paymentMode=partner.getPaymentMode();
  }
  if (paymentMode == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_4),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setPaymentMode(paymentMode);
  if (mainInvoicingAddress == null) {
    mainInvoicingAddress=Beans.get(PartnerService.class).getInvoicingAddress(partner);
  }
  if (mainInvoicingAddress == null && partner.getIsCustomer()) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_5),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setAddress(mainInvoicingAddress);
  invoice.setContactPartner(contactPartner);
  if (currency == null) {
    currency=partner.getCurrency();
  }
  if (currency == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_GENERATOR_6),GeneralServiceImpl.EXCEPTION),IException.MISSING_FIELD);
  }
  invoice.setCurrency(currency);
  invoice.setCompany(company);
  invoice.setPartnerAccount(Beans.get(AccountCustomerService.class).getPartnerAccount(partner,company,operationType == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || operationType == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND));
  invoice.setJournal(journalService.getJournal(invoice));
  invoice.setStatusSelect(InvoiceRepository.STATUS_DRAFT);
  if (priceList == null) {
    if (InvoiceToolService.isPurchase(invoice)) {
      priceList=partner.getPurchasePriceList();
    }
 else {
      priceList=partner.getSalePriceList();
    }
  }
  invoice.setPriceList(priceList);
  invoice.setInternalReference(internalReference);
  invoice.setExternalReference(externalReference);
  invoice.setInAti(inAti);
  invoice.setInvoiceDate(today);
  if (invoice.getPaymentCondition() != null) {
    invoice.setDueDate(InvoiceToolService.getDueDate(invoice.getPaymentCondition(),invoice.getInvoiceDate()));
  }
  initCollections(invoice);
  return invoice;
}