Program: 58905
Project: 58905
Buggy source:
public List<InvoiceLine> createInvoiceLine(Invoice invoice,TimesheetLine timesheetLine) throws AxelorException {
  Product product=null;
  Employee employee=timesheetLine.getUser().getEmployee();
  product=timesheetLine.getProduct();
  if (product == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_PRODUCT)),IException.CONFIGURATION_ERROR);
  }
  BigDecimal qtyConverted=timesheetLine.getDurationStored();
  if (employee != null) {
    if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_DAYS) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitDays(),timesheetLine.getDurationStored());
    }
 else     if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_MINUTES) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitMinutes(),timesheetLine.getDurationStored());
    }
  }
  InvoiceLineGenerator invoiceLineGenerator=new InvoiceLineGenerator(invoice,product,product.getName(),null,qtyConverted,product.getUnit(),InvoiceLineGenerator.DEFAULT_SEQUENCE,false){
    @Override public List<InvoiceLine> creates() throws AxelorException {
      InvoiceLine invoiceLine=this.createInvoiceLine();
      List<InvoiceLine> invoiceLines=new ArrayList<InvoiceLine>();
      invoiceLines.add(invoiceLine);
      return invoiceLines;
    }
  }
;
  return invoiceLineGenerator.creates();
}

Fixed version (ground truth):
public List<InvoiceLine> createInvoiceLine(Invoice invoice,TimesheetLine timesheetLine) throws AxelorException {
  Product product=null;
  Employee employee=timesheetLine.getUser().getEmployee();
  int discountTypeSelect=1;
  product=timesheetLine.getProduct();
  if (product == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.TIMESHEET_PRODUCT)),IException.CONFIGURATION_ERROR);
  }
  BigDecimal price=product.getSalePrice();
  BigDecimal discountAmount=product.getCostPrice();
  BigDecimal qtyConverted=timesheetLine.getDurationStored();
  if (employee != null) {
    if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_DAYS) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitDays(),timesheetLine.getDurationStored());
    }
 else     if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_MINUTES) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitMinutes(),timesheetLine.getDurationStored());
    }
  }
  PriceList priceList=invoice.getPartner().getSalePriceList();
  if (priceList != null) {
    PriceListLine priceListLine=priceListService.getPriceListLine(product,qtyConverted,priceList);
    if (priceListLine != null) {
      discountTypeSelect=priceListLine.getTypeSelect();
    }
    if ((GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == IPriceListLine.TYPE_REPLACE) || GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.INCLUDE_DISCOUNT) {
      Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
      discountAmount=(BigDecimal)discounts.get("String_Node_Str");
      price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),discountAmount);
    }
 else {
      Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
      discountAmount=(BigDecimal)discounts.get("String_Node_Str");
      if (discounts.get("String_Node_Str") != null) {
        price=(BigDecimal)discounts.get("String_Node_Str");
      }
    }
  }
  InvoiceLineGenerator invoiceLineGenerator=new InvoiceLineGenerator(invoice,product,product.getName(),price,null,qtyConverted,product.getUnit(),InvoiceLineGenerator.DEFAULT_SEQUENCE,discountAmount,discountTypeSelect,price.multiply(qtyConverted),null,false){
    @Override public List<InvoiceLine> creates() throws AxelorException {
      InvoiceLine invoiceLine=this.createInvoiceLine();
      List<InvoiceLine> invoiceLines=new ArrayList<InvoiceLine>();
      invoiceLines.add(invoiceLine);
      return invoiceLines;
    }
  }
;
  return invoiceLineGenerator.creates();
}