Program: 58789
Project: 58789
Buggy source:
@Override public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder,Product product,String description,BigDecimal qty,Unit unit) throws AxelorException {
  PurchaseOrderLine purchaseOrderLine=new PurchaseOrderLine();
  purchaseOrderLine.setPurchaseOrder(purchaseOrder);
  purchaseOrderLine.setEstimatedDelivDate(purchaseOrder.getDeliveryDate());
  purchaseOrderLine.setDescription(description);
  purchaseOrderLine.setIsOrdered(false);
  purchaseOrderLine.setProduct(product);
  purchaseOrderLine.setProductName(product.getName());
  purchaseOrderLine.setQty(qty);
  purchaseOrderLine.setSequence(sequence);
  sequence++;
  purchaseOrderLine.setUnit(unit);
  purchaseOrderLine.setTaxLine(this.getTaxLine(purchaseOrder,purchaseOrderLine));
  BigDecimal price=this.getUnitPrice(purchaseOrder,purchaseOrderLine);
  PriceList priceList=purchaseOrder.getPriceList();
  if (priceList != null) {
    PriceListLine priceListLine=this.getPriceListLine(purchaseOrderLine,priceList);
    Map<String,Object> discounts=priceListService.getDiscounts(priceList,priceListLine,price);
    purchaseOrderLine.setDiscountAmount((BigDecimal)discounts.get("String_Node_Str"));
    purchaseOrderLine.setDiscountTypeSelect((Integer)discounts.get("String_Node_Str"));
    if (discounts.get("String_Node_Str") != null) {
      price=(BigDecimal)discounts.get("String_Node_Str");
    }
  }
  purchaseOrderLine.setPrice(price);
  purchaseOrderLine.setPrice(this.convertUnitPrice(purchaseOrderLine,purchaseOrder));
  purchaseOrderLine.setDiscountAmount(this.convertDiscountAmount(purchaseOrderLine,purchaseOrder));
  if (!purchaseOrder.getInAti()) {
    BigDecimal exTaxTotal=PurchaseOrderLineServiceImpl.computeAmount(purchaseOrderLine.getQty(),this.computeDiscount(purchaseOrderLine));
    BigDecimal inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(purchaseOrderLine.getTaxLine().getValue()));
    BigDecimal priceDiscounted=this.computeDiscount(purchaseOrderLine);
    BigDecimal companyExTaxTotal=this.getCompanyExTaxTotal(exTaxTotal,purchaseOrder);
    BigDecimal companyInTaxTotal=companyExTaxTotal.add(companyExTaxTotal.multiply(purchaseOrderLine.getTaxLine().getValue()));
    purchaseOrderLine.setExTaxTotal(exTaxTotal);
    purchaseOrderLine.setCompanyExTaxTotal(companyExTaxTotal);
    purchaseOrderLine.setCompanyInTaxTotal(companyInTaxTotal);
    purchaseOrderLine.setInTaxTotal(inTaxTotal);
    purchaseOrderLine.setPriceDiscounted(priceDiscounted);
  }
 else {
    BigDecimal inTaxTotal=PurchaseOrderLineServiceImpl.computeAmount(purchaseOrderLine.getQty(),this.computeDiscount(purchaseOrderLine));
    BigDecimal exTaxTotal=inTaxTotal.divide(purchaseOrderLine.getTaxLine().getValue().add(new BigDecimal(1)),2,BigDecimal.ROUND_HALF_UP);
    BigDecimal priceDiscounted=this.computeDiscount(purchaseOrderLine);
    BigDecimal companyInTaxTotal=this.getCompanyExTaxTotal(inTaxTotal,purchaseOrder);
    BigDecimal companyExTaxTotal=companyInTaxTotal.divide(purchaseOrderLine.getTaxLine().getValue().add(new BigDecimal(1)),2,BigDecimal.ROUND_HALF_UP);
    purchaseOrderLine.setExTaxTotal(exTaxTotal);
    purchaseOrderLine.setCompanyExTaxTotal(companyExTaxTotal);
    purchaseOrderLine.setCompanyExTaxTotal(companyInTaxTotal);
    purchaseOrderLine.setInTaxTotal(inTaxTotal);
    purchaseOrderLine.setPriceDiscounted(priceDiscounted);
  }
  return purchaseOrderLine;
}

Fixed version (ground truth):
@Override public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder,Product product,String description,BigDecimal qty,Unit unit) throws AxelorException {
  PurchaseOrderLine purchaseOrderLine=new PurchaseOrderLine();
  purchaseOrderLine.setPurchaseOrder(purchaseOrder);
  purchaseOrderLine.setEstimatedDelivDate(purchaseOrder.getDeliveryDate());
  purchaseOrderLine.setDescription(description);
  purchaseOrderLine.setIsOrdered(false);
  purchaseOrderLine.setProduct(product);
  purchaseOrderLine.setProductName(product.getName());
  purchaseOrderLine.setQty(qty);
  purchaseOrderLine.setSequence(sequence);
  sequence++;
  purchaseOrderLine.setUnit(unit);
  TaxLine taxLine=this.getTaxLine(purchaseOrder,purchaseOrderLine);
  purchaseOrderLine.setTaxLine(taxLine);
  BigDecimal price=this.getUnitPrice(purchaseOrder,purchaseOrderLine,taxLine);
  Map<String,Object> discounts=this.getDiscount(purchaseOrder,purchaseOrderLine,price);
  purchaseOrderLine.setDiscountAmount((BigDecimal)discounts.get("String_Node_Str"));
  purchaseOrderLine.setDiscountTypeSelect((Integer)discounts.get("String_Node_Str"));
  if (discounts.get("String_Node_Str") != null) {
    price=(BigDecimal)discounts.get("String_Node_Str");
  }
  purchaseOrderLine.setPrice(price);
  purchaseOrderLine.setPriceDiscounted(this.computeDiscount(purchaseOrderLine));
  BigDecimal exTaxTotal, inTaxTotal, companyExTaxTotal, companyInTaxTotal;
  if (!purchaseOrder.getInAti()) {
    exTaxTotal=PurchaseOrderLineServiceImpl.computeAmount(purchaseOrderLine.getQty(),this.computeDiscount(purchaseOrderLine));
    inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(purchaseOrderLine.getTaxLine().getValue()));
    companyExTaxTotal=this.getCompanyExTaxTotal(exTaxTotal,purchaseOrder);
    companyInTaxTotal=companyExTaxTotal.add(companyExTaxTotal.multiply(purchaseOrderLine.getTaxLine().getValue()));
  }
 else {
    inTaxTotal=PurchaseOrderLineServiceImpl.computeAmount(purchaseOrderLine.getQty(),this.computeDiscount(purchaseOrderLine));
    exTaxTotal=inTaxTotal.divide(purchaseOrderLine.getTaxLine().getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
    companyInTaxTotal=this.getCompanyExTaxTotal(inTaxTotal,purchaseOrder);
    companyExTaxTotal=companyInTaxTotal.divide(purchaseOrderLine.getTaxLine().getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
  }
  purchaseOrderLine.setExTaxTotal(exTaxTotal);
  purchaseOrderLine.setCompanyExTaxTotal(companyExTaxTotal);
  purchaseOrderLine.setCompanyInTaxTotal(companyInTaxTotal);
  purchaseOrderLine.setInTaxTotal(inTaxTotal);
  return purchaseOrderLine;
}