Program: 58826
Project: 58826
Buggy source:
protected InvoiceLineGeneratorSupplyChain(Invoice invoice,Product product,String productName,String description,BigDecimal qty,Unit unit,int sequence,boolean isTaxInvoice,SaleOrderLine saleOrderLine,PurchaseOrderLine purchaseOrderLine,StockMove stockMove,Subscription subscription,StockMoveLine stockMoveLine) throws AxelorException {
  super(invoice,product,productName,description,qty,unit,sequence,isTaxInvoice);
  if (subscription != null) {
    this.subscription=subscription;
  }
  if (saleOrderLine != null) {
    this.saleOrderLine=saleOrderLine;
    this.discountAmount=saleOrderLine.getDiscountAmount();
    this.price=saleOrderLine.getPrice();
    this.priceDiscounted=saleOrderLine.getPriceDiscounted();
    this.taxLine=saleOrderLine.getTaxLine();
    this.discountTypeSelect=saleOrderLine.getDiscountTypeSelect();
    this.groupingLine=saleOrderLine.getGroupingLine();
    this.exTaxTotal=saleOrderLine.getExTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    this.inTaxTotal=saleOrderLine.getInTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    if (ProductRepository.PRODUCT_TYPE_SUBSCRIPTABLE.equals(saleOrderLine.getProduct().getProductTypeSelect()) && saleOrderLine.getSubscriptionList() != null && !saleOrderLine.getSubscriptionList().isEmpty()) {
      this.exTaxTotal=this.exTaxTotal.divide(new BigDecimal(saleOrderLine.getSubscriptionList().size())).setScale(2,RoundingMode.HALF_EVEN);
      this.inTaxTotal=this.inTaxTotal.divide(new BigDecimal(saleOrderLine.getSubscriptionList().size())).setScale(2,RoundingMode.HALF_EVEN);
    }
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : saleOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
 else   if (purchaseOrderLine != null) {
    this.purchaseOrderLine=purchaseOrderLine;
    this.discountAmount=purchaseOrderLine.getDiscountAmount();
    this.price=purchaseOrderLine.getPrice();
    this.priceDiscounted=purchaseOrderLine.getPriceDiscounted();
    this.taxLine=purchaseOrderLine.getTaxLine();
    this.discountTypeSelect=purchaseOrderLine.getDiscountTypeSelect();
    this.exTaxTotal=purchaseOrderLine.getExTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    this.inTaxTotal=purchaseOrderLine.getInTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : purchaseOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
  if (stockMoveLine != null) {
    this.price=stockMoveLine.getUnitPriceUntaxed();
    this.priceDiscounted=stockMoveLine.getUnitPriceUntaxed();
    if (!invoice.getInAti()) {
      this.exTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed()).setScale(2,RoundingMode.HALF_EVEN);
      if (taxLine != null) {
        this.inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue())).setScale(2,RoundingMode.HALF_EVEN);
      }
    }
 else {
      this.inTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed()).setScale(2,RoundingMode.HALF_EVEN);
      if (taxLine != null) {
        this.exTaxTotal=inTaxTotal.divide(taxLine.getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
      }
    }
    if (purchaseOrderLine == null && saleOrderLine == null) {
      this.taxLine=Beans.get(AccountManagementService.class).getTaxLine(Beans.get(GeneralService.class).getTodayDate(),stockMoveLine.getProduct(),invoice.getCompany(),invoice.getPartner().getFiscalPosition(),invoice.getOperationTypeSelect() < InvoiceRepository.OPERATION_TYPE_CLIENT_SALE);
      if (!invoice.getInAti()) {
        if (price != null && qty != null) {
          exTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice)).setScale(2,RoundingMode.HALF_EVEN);
          inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue())).setScale(2,RoundingMode.HALF_EVEN);
        }
      }
 else {
        if (price != null && qty != null) {
          inTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice)).setScale(2,RoundingMode.HALF_EVEN);
          exTaxTotal=inTaxTotal.divide(taxLine.getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
        }
      }
    }
  }
  if (stockMove != null) {
    this.stockMove=stockMove;
  }
}

Fixed version (ground truth):
protected InvoiceLineGeneratorSupplyChain(Invoice invoice,Product product,String productName,String description,BigDecimal qty,Unit unit,int sequence,boolean isTaxInvoice,SaleOrderLine saleOrderLine,PurchaseOrderLine purchaseOrderLine,StockMove stockMove,Subscription subscription,StockMoveLine stockMoveLine) throws AxelorException {
  super(invoice,product,productName,description,qty,unit,sequence,isTaxInvoice);
  if (subscription != null) {
    this.subscription=subscription;
  }
  if (saleOrderLine != null) {
    this.saleOrderLine=saleOrderLine;
    this.discountAmount=saleOrderLine.getDiscountAmount();
    this.price=saleOrderLine.getPrice();
    this.priceDiscounted=saleOrderLine.getPriceDiscounted();
    this.taxLine=saleOrderLine.getTaxLine();
    this.discountTypeSelect=saleOrderLine.getDiscountTypeSelect();
    this.groupingLine=saleOrderLine.getGroupingLine();
    this.exTaxTotal=saleOrderLine.getExTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    this.inTaxTotal=saleOrderLine.getInTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    if (ProductRepository.PRODUCT_TYPE_SUBSCRIPTABLE.equals(saleOrderLine.getProduct().getProductTypeSelect()) && saleOrderLine.getSubscriptionList() != null && !saleOrderLine.getSubscriptionList().isEmpty()) {
      this.exTaxTotal=this.exTaxTotal.divide(new BigDecimal(saleOrderLine.getSubscriptionList().size())).setScale(2,RoundingMode.HALF_EVEN);
      this.inTaxTotal=this.inTaxTotal.divide(new BigDecimal(saleOrderLine.getSubscriptionList().size())).setScale(2,RoundingMode.HALF_EVEN);
    }
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : saleOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
 else   if (purchaseOrderLine != null) {
    this.purchaseOrderLine=purchaseOrderLine;
    this.discountAmount=purchaseOrderLine.getDiscountAmount();
    this.price=purchaseOrderLine.getPrice();
    this.priceDiscounted=purchaseOrderLine.getPriceDiscounted();
    this.taxLine=purchaseOrderLine.getTaxLine();
    this.discountTypeSelect=purchaseOrderLine.getDiscountTypeSelect();
    this.exTaxTotal=purchaseOrderLine.getExTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    this.inTaxTotal=purchaseOrderLine.getInTaxTotal().setScale(2,RoundingMode.HALF_EVEN);
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : purchaseOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
  if (stockMoveLine != null && purchaseOrderLine == null && saleOrderLine == null) {
    this.price=stockMoveLine.getUnitPriceUntaxed();
    this.priceDiscounted=stockMoveLine.getUnitPriceUntaxed();
    if (taxLine == null) {
      this.taxLine=Beans.get(AccountManagementService.class).getTaxLine(Beans.get(GeneralService.class).getTodayDate(),stockMoveLine.getProduct(),invoice.getCompany(),invoice.getPartner().getFiscalPosition(),invoice.getOperationTypeSelect() < InvoiceRepository.OPERATION_TYPE_CLIENT_SALE);
    }
    if (!invoice.getInAti()) {
      this.exTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed()).setScale(2,RoundingMode.HALF_EVEN);
      if (taxLine != null) {
        this.inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue())).setScale(2,RoundingMode.HALF_EVEN);
      }
    }
 else {
      this.inTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed()).setScale(2,RoundingMode.HALF_EVEN);
      if (taxLine != null) {
        this.exTaxTotal=inTaxTotal.divide(taxLine.getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
      }
    }
    if (!invoice.getInAti()) {
      if (price != null && qty != null) {
        exTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice)).setScale(2,RoundingMode.HALF_EVEN);
        if (taxLine != null) {
          inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue())).setScale(2,RoundingMode.HALF_EVEN);
        }
      }
    }
 else {
      if (price != null && qty != null) {
        inTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice)).setScale(2,RoundingMode.HALF_EVEN);
        if (taxLine != null) {
          exTaxTotal=inTaxTotal.divide(taxLine.getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
        }
      }
    }
  }
  if (stockMove != null) {
    this.stockMove=stockMove;
  }
}