Program: 58901
Project: 58901
Buggy source:
public List<InvoiceLine> createInvoiceLine(Invoice invoice,TimesheetLine timesheetLine,int priority) 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.getVisibleDuration();
  qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitHours(),timesheetLine.getVisibleDuration());
  Unit unit=GeneralService.getGeneral().getUnitHours();
  if (employee != null) {
    if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_DAYS) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitDays(),timesheetLine.getVisibleDuration());
      unit=GeneralService.getGeneral().getUnitDays();
    }
 else     if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_MINUTES) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(product.getUnit(),GeneralService.getGeneral().getUnitMinutes(),timesheetLine.getVisibleDuration());
      unit=GeneralService.getGeneral().getUnitMinutes();
    }
  }
  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,unit,priority,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();
}

Fixed version (ground truth):
public List<InvoiceLine> createInvoiceLine(Invoice invoice,TimesheetLine timesheetLine,int priority) 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.getVisibleDuration();
  qtyConverted=Beans.get(UnitConversionService.class).convert(GeneralService.getGeneral().getUnitHours(),product.getUnit(),timesheetLine.getVisibleDuration());
  if (employee != null) {
    if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_DAYS) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(GeneralService.getGeneral().getUnitDays(),product.getUnit(),timesheetLine.getVisibleDuration());
    }
 else     if (employee.getTimeLoggingPreferenceSelect() == EmployeeRepository.TIME_PREFERENCE_MINUTES) {
      qtyConverted=Beans.get(UnitConversionService.class).convert(GeneralService.getGeneral().getUnitMinutes(),product.getUnit(),timesheetLine.getVisibleDuration());
    }
  }
  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(),priority,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();
}