use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class InvoiceLineServiceImpl method getUnitPrice.
/**
* A function used to get the unit price of an invoice line, either in ati or wt
*
* @param invoice the invoice containing the invoice line
* @param invoiceLine
* @param taxLine the tax line applied to the unit price
* @param isPurchase
* @param resultInAti whether or not you want the result unit price in ati
* @return the unit price of the invoice line
* @throws AxelorException
*/
private BigDecimal getUnitPrice(Invoice invoice, InvoiceLine invoiceLine, TaxLine taxLine, boolean isPurchase, boolean resultInAti) throws AxelorException {
Product product = invoiceLine.getProduct();
BigDecimal price = null;
Currency productCurrency;
if (isPurchase) {
price = (BigDecimal) productCompanyService.get(product, "purchasePrice", invoice.getCompany());
productCurrency = (Currency) productCompanyService.get(product, "purchaseCurrency", invoice.getCompany());
} else {
price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
productCurrency = (Currency) productCompanyService.get(product, "saleCurrency", invoice.getCompany());
}
if ((Boolean) productCompanyService.get(product, "inAti", invoice.getCompany()) != resultInAti) {
price = this.convertUnitPrice((Boolean) productCompanyService.get(product, "inAti", invoice.getCompany()), taxLine, price);
}
return currencyService.getAmountCurrencyConvertedAtDate(productCurrency, invoice.getCurrency(), price, invoice.getInvoiceDate()).setScale(appAccountService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Aggregations