Program: 58831
Project: 58831
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();
    this.inTaxTotal=saleOrderLine.getInTaxTotal();
    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(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,RoundingMode.HALF_EVEN);
      this.inTaxTotal=this.inTaxTotal.divide(new BigDecimal(saleOrderLine.getSubscriptionList().size())).setScale(IAdministration.DEFAULT_NB_DECIMAL_DIGITS,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();
    this.inTaxTotal=purchaseOrderLine.getInTaxTotal();
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : purchaseOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
 else   if (stockMoveLine != null) {
    this.price=stockMoveLine.getUnitPriceUntaxed();
    this.priceDiscounted=stockMoveLine.getUnitPriceUntaxed();
    this.exTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed());
    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));
        inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue()));
      }
    }
 else {
      if (price != null && qty != null) {
        inTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice));
        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();
    this.inTaxTotal=saleOrderLine.getInTaxTotal();
    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();
    this.inTaxTotal=purchaseOrderLine.getInTaxTotal();
    analyticDistributionLineList=new ArrayList<AnalyticDistributionLine>();
    for (    AnalyticDistributionLine analyticDistributionLineIt : purchaseOrderLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLineList.add(analyticDistributionLine);
    }
  }
 else   if (stockMoveLine != null) {
    this.price=stockMoveLine.getUnitPriceUntaxed();
    this.priceDiscounted=stockMoveLine.getUnitPriceUntaxed();
    this.exTaxTotal=qty.multiply(stockMoveLine.getUnitPriceUntaxed());
    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));
        inTaxTotal=exTaxTotal.add(exTaxTotal.multiply(taxLine.getValue()));
      }
    }
 else {
      if (price != null && qty != null) {
        inTaxTotal=InvoiceLineManagement.computeAmount(qty,Beans.get(InvoiceLineService.class).computeDiscount(discountTypeSelect,discountAmount,price,invoice));
        exTaxTotal=inTaxTotal.divide(taxLine.getValue().add(BigDecimal.ONE),2,BigDecimal.ROUND_HALF_UP);
      }
    }
  }
  if (stockMove != null) {
    this.stockMove=stockMove;
  }
}