Program: 58900
Project: 58900
Buggy source:
public void getDiscount(ActionRequest request,ActionResponse response) throws AxelorException {
  InvoiceLine invoiceLine=request.getContext().asType(InvoiceLine.class);
  Invoice invoice=invoiceLine.getInvoice();
  if (invoice == null) {
    invoice=request.getContext().getParentContext().asType(Invoice.class);
  }
  if (invoice != null && invoiceLine.getProduct() != null) {
    try {
      BigDecimal price=invoiceLine.getPrice();
      if (price.compareTo(BigDecimal.ZERO) == 0) {
        price=invoiceLine.getProduct().getSalePrice();
      }
      if (invoice.getOperationTypeSelect() < 2) {
        price=invoiceLine.getPrice();
        if (price.compareTo(BigDecimal.ZERO) == 0) {
          price=invoiceLine.getProduct().getPurchasePrice();
        }
      }
      PriceList priceList=invoice.getPriceList();
      int discountTypeSelect=0;
      BigDecimal discountAmount=BigDecimal.ZERO;
      if (priceList != null) {
        PriceListLine priceListLine=invoiceLineService.getPriceListLine(invoiceLine,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");
          response.setValue("String_Node_Str",discountAmount);
          response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
          if (discounts.get("String_Node_Str") != null) {
            price=(BigDecimal)discounts.get("String_Node_Str");
          }
        }
      }
      if (invoice.getOperationTypeSelect() < InvoiceRepository.OPERATION_TYPE_CLIENT_SALE && discountAmount.equals(BigDecimal.ZERO)) {
        List<SupplierCatalog> supplierCatalogList=invoiceLine.getProduct().getSupplierCatalogList();
        if (supplierCatalogList != null && !supplierCatalogList.isEmpty()) {
          SupplierCatalog supplierCatalog=Beans.get(SupplierCatalogRepository.class).all().filter("String_Node_Str",invoiceLine.getProduct(),invoiceLine.getQty(),invoice.getPartner()).fetchOne();
          if (supplierCatalog != null) {
            if (GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.DISCOUNT_SEPARATE) {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
            }
 else {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),(BigDecimal)discounts.get("String_Node_Str"));
            }
          }
        }
      }
      response.setValue("String_Node_Str",price);
    }
 catch (    Exception e) {
      response.setFlash(e.getMessage());
    }
  }
}

Fixed version (ground truth):
public void getDiscount(ActionRequest request,ActionResponse response) throws AxelorException {
  InvoiceLine invoiceLine=request.getContext().asType(InvoiceLine.class);
  Invoice invoice=invoiceLine.getInvoice();
  if (invoice == null) {
    invoice=request.getContext().getParentContext().asType(Invoice.class);
  }
  if (invoice != null && invoiceLine.getProduct() != null) {
    try {
      BigDecimal price=invoiceLine.getPrice();
      PriceList priceList=invoice.getPriceList();
      int discountTypeSelect=0;
      BigDecimal discountAmount=BigDecimal.ZERO;
      if (priceList != null) {
        PriceListLine priceListLine=invoiceLineService.getPriceListLine(invoiceLine,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");
          response.setValue("String_Node_Str",discountAmount);
          response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
          if (discounts.get("String_Node_Str") != null) {
            price=(BigDecimal)discounts.get("String_Node_Str");
          }
        }
      }
      if (invoice.getOperationTypeSelect() < InvoiceRepository.OPERATION_TYPE_CLIENT_SALE && discountAmount.equals(BigDecimal.ZERO)) {
        List<SupplierCatalog> supplierCatalogList=invoiceLine.getProduct().getSupplierCatalogList();
        if (supplierCatalogList != null && !supplierCatalogList.isEmpty()) {
          SupplierCatalog supplierCatalog=Beans.get(SupplierCatalogRepository.class).all().filter("String_Node_Str",invoiceLine.getProduct(),invoiceLine.getQty(),invoice.getPartner()).fetchOne();
          if (supplierCatalog != null) {
            if (GeneralService.getGeneral().getComputeMethodDiscountSelect() == GeneralRepository.DISCOUNT_SEPARATE) {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
              response.setValue("String_Node_Str",discounts.get("String_Node_Str"));
            }
 else {
              Map<String,Object> discounts=productService.getDiscountsFromCatalog(supplierCatalog,price);
              price=priceListService.computeDiscount(price,(int)discounts.get("String_Node_Str"),(BigDecimal)discounts.get("String_Node_Str"));
            }
          }
        }
      }
      response.setValue("String_Node_Str",price);
    }
 catch (    Exception e) {
      response.setFlash(e.getMessage());
    }
  }
}