Program: 58909
Project: 58909
Buggy source:
/** 
 * @return
 * @throws AxelorException
 */
protected InvoiceLine createInvoiceLine() throws AxelorException {
  InvoiceLine invoiceLine=new InvoiceLine();
  invoiceLine.setInvoice(invoice);
  invoiceLine.setProduct(product);
  invoiceLine.setProductName(productName);
  invoiceLine.setDescription(description);
  Partner partner=invoice.getPartner();
  if (taxLine == null) {
    boolean isPurchase=false;
    if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
      isPurchase=true;
    }
    taxLine=accountManagementServiceImpl.getTaxLine(today,product,invoice.getCompany(),partner.getFiscalPosition(),isPurchase);
  }
  invoiceLine.setTaxLine(taxLine);
  invoiceLine.setPrice(price);
  if (priceDiscounted != null)   invoiceLine.setPriceDiscounted(priceDiscounted);
  invoiceLine.setQty(qty);
  invoiceLine.setUnit(unit);
  if (exTaxTotal == null || inTaxTotal == null) {
    price=this.convertUnitPrice(invoiceLine,invoice).setScale(2,BigDecimal.ROUND_HALF_UP);
    invoiceLine.setPrice(price);
    if (!invoice.getInAti()) {
      exTaxTotal=computeAmount(qty,price);
      inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(invoiceLine.getTaxLine().getValue()));
    }
 else {
      inTaxTotal=computeAmount(qty,price);
      exTaxTotal=inTaxTotal.divide(invoiceLine.getTaxLine().getValue().add(new BigDecimal(1)),2,BigDecimal.ROUND_HALF_UP);
    }
  }
  invoiceLine.setExTaxTotal(exTaxTotal);
  invoiceLine.setInTaxTotal(inTaxTotal);
  Company company=invoice.getCompany();
  Currency companyCurrency=company.getCurrency();
  if (companyCurrency == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_LINE_GENERATOR_2),company.getName()),IException.CONFIGURATION_ERROR);
  }
  invoiceLine.setCompanyExTaxTotal(currencyService.getAmountCurrencyConverted(invoice.getCurrency(),companyCurrency,exTaxTotal,today).setScale(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,RoundingMode.HALF_UP));
  invoiceLine.setCompanyInTaxTotal(currencyService.getAmountCurrencyConverted(invoice.getCurrency(),companyCurrency,inTaxTotal,today).setScale(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,RoundingMode.HALF_UP));
  if (taxLine == null) {
    boolean isPurchase=false;
    if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
      isPurchase=true;
    }
    taxLine=accountManagementServiceImpl.getTaxLine(today,product,invoice.getCompany(),partner.getFiscalPosition(),isPurchase);
  }
  invoiceLine.setTaxLine(taxLine);
  invoiceLine.setGroupingLine(groupingLine);
  invoiceLine.setSequence(sequence);
  invoiceLine.setDiscountTypeSelect(discountTypeSelect);
  invoiceLine.setDiscountAmount(discountAmount);
  return invoiceLine;
}

Fixed version (ground truth):
/** 
 * @return
 * @throws AxelorException
 */
protected InvoiceLine createInvoiceLine() throws AxelorException {
  InvoiceLine invoiceLine=new InvoiceLine();
  invoiceLine.setInvoice(invoice);
  invoiceLine.setProduct(product);
  invoiceLine.setProductName(productName);
  invoiceLine.setDescription(description);
  Partner partner=invoice.getPartner();
  if (taxLine == null) {
    boolean isPurchase=false;
    if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
      isPurchase=true;
    }
    taxLine=accountManagementServiceImpl.getTaxLine(today,product,invoice.getCompany(),partner.getFiscalPosition(),isPurchase);
  }
  invoiceLine.setTaxLine(taxLine);
  invoiceLine.setPrice(price);
  if (priceDiscounted != null)   invoiceLine.setPriceDiscounted(priceDiscounted);
  invoiceLine.setQty(qty);
  invoiceLine.setUnit(unit);
  if (exTaxTotal == null || inTaxTotal == null) {
    price=this.convertUnitPrice(invoiceLine,invoice).setScale(GeneralService.getNbDecimalDigitForUnitPrice(),BigDecimal.ROUND_HALF_UP);
    invoiceLine.setPrice(price);
    if (!invoice.getInAti()) {
      exTaxTotal=computeAmount(qty,price);
      inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(invoiceLine.getTaxLine().getValue()));
    }
 else {
      inTaxTotal=computeAmount(qty,price);
      exTaxTotal=inTaxTotal.divide(invoiceLine.getTaxLine().getValue().add(new BigDecimal(1)),2,BigDecimal.ROUND_HALF_UP);
    }
  }
  invoiceLine.setExTaxTotal(exTaxTotal);
  invoiceLine.setInTaxTotal(inTaxTotal);
  Company company=invoice.getCompany();
  Currency companyCurrency=company.getCurrency();
  if (companyCurrency == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.INVOICE_LINE_GENERATOR_2),company.getName()),IException.CONFIGURATION_ERROR);
  }
  invoiceLine.setCompanyExTaxTotal(currencyService.getAmountCurrencyConverted(invoice.getCurrency(),companyCurrency,exTaxTotal,today).setScale(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,RoundingMode.HALF_UP));
  invoiceLine.setCompanyInTaxTotal(currencyService.getAmountCurrencyConverted(invoice.getCurrency(),companyCurrency,inTaxTotal,today).setScale(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,RoundingMode.HALF_UP));
  if (taxLine == null) {
    boolean isPurchase=false;
    if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
      isPurchase=true;
    }
    taxLine=accountManagementServiceImpl.getTaxLine(today,product,invoice.getCompany(),partner.getFiscalPosition(),isPurchase);
  }
  invoiceLine.setTaxLine(taxLine);
  invoiceLine.setGroupingLine(groupingLine);
  invoiceLine.setSequence(sequence);
  invoiceLine.setDiscountTypeSelect(discountTypeSelect);
  invoiceLine.setDiscountAmount(discountAmount);
  return invoiceLine;
}