use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateCutOffMove.
public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
return null;
}
Company company = stockMove.getCompany();
AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
Partner partner = stockMove.getPartner();
Account partnerAccount = null;
Currency currency = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
currency = saleOrder.getCurrency();
if (partner == null) {
partner = saleOrder.getClientPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
}
if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
currency = purchaseOrder.getCurrency();
if (partner == null) {
partner = purchaseOrder.getSupplierPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
}
String origin = stockMove.getStockMoveSeq();
Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
counter = 0;
this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
move.setStockMove(stockMove);
moveValidateService.validate(move);
} else {
moveRepository.remove(move);
return null;
}
return move;
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class MoveLineController method computeCurrentRate.
public void computeCurrentRate(ActionRequest request, ActionResponse response) {
try {
Context parentContext = request.getContext().getParent();
BigDecimal currencyRate = BigDecimal.ONE;
if (parentContext != null && Move.class.equals(parentContext.getContextClass())) {
Move move = parentContext.asType(Move.class);
Currency currency = move.getCurrency();
Currency companyCurrency = move.getCompanyCurrency();
if (currency != null && companyCurrency != null && !currency.equals(companyCurrency)) {
currencyRate = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, companyCurrency);
}
}
response.setValue("currencyRate", currencyRate);
} catch (AxelorException e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class BankOrderCreateServiceHr method createBankOrder.
/**
* Method to create a bank order for an expense
*
* @param expense An expense
* @throws AxelorException
*/
public BankOrder createBankOrder(Expense expense, BankDetails bankDetails) throws AxelorException {
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
PaymentMode paymentMode = expense.getPaymentMode();
BigDecimal amount = expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount());
Currency currency = company.getCurrency();
LocalDate paymentDate = Beans.get(AppBaseService.class).getTodayDate(company);
BankOrder bankOrder = super.createBankOrder(paymentMode, BankOrderRepository.PARTNER_TYPE_EMPLOYEE, paymentDate, company, bankDetails, currency, expense.getFullName(), expense.getFullName(), BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
bankOrder.addBankOrderLineListItem(bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), partner, amount, currency, paymentDate, expense.getExpenseSeq(), expense.getFullName(), expense));
bankOrder = bankOrderRepo.save(bankOrder);
return bankOrder;
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class SaleOrderController method createSaleOrder.
@SuppressWarnings("unchecked")
public void createSaleOrder(ActionRequest request, ActionResponse response) throws AxelorException {
SaleOrder origin = Beans.get(SaleOrderRepository.class).find(Long.parseLong(request.getContext().get("_idCopy").toString()));
if (origin != null) {
LinkedHashMap<String, Object> wizardCurrencyContext = (LinkedHashMap<String, Object>) request.getContext().get("_wizardCurrency");
Integer wizardCurrencyId = (Integer) wizardCurrencyContext.get("id");
Currency wizardCurrency = Beans.get(CurrencyRepository.class).find(Long.valueOf(wizardCurrencyId));
PriceList wizardPriceList = null;
if (request.getContext().get("_wizardPriceList") != null) {
LinkedHashMap<String, Object> wizardPriceListContext = (LinkedHashMap<String, Object>) request.getContext().get("_wizardPriceList");
Integer wizardPriceListId = (Integer) wizardPriceListContext.get("id");
wizardPriceList = Beans.get(PriceListRepository.class).find(Long.valueOf(wizardPriceListId));
}
SaleOrder copy = Beans.get(SaleOrderCreateService.class).createSaleOrder(origin, wizardCurrency, wizardPriceList);
response.setValues(Mapper.toMap(copy));
}
}
use of com.axelor.apps.base.db.Currency in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method getUnitPrice.
/**
* A function used to get the unit price of a sale order line, either in ati or wt
*
* @param saleOrder the sale order containing the sale order line
* @param saleOrderLine
* @param taxLine the tax applied to the unit price
* @param resultInAti whether you want the result in ati or not
* @return the unit price of the sale order line
* @throws AxelorException
*/
private BigDecimal getUnitPrice(SaleOrder saleOrder, SaleOrderLine saleOrderLine, TaxLine taxLine, boolean resultInAti) throws AxelorException {
Product product = saleOrderLine.getProduct();
Boolean productInAti = (Boolean) productCompanyService.get(product, "inAti", saleOrder.getCompany());
BigDecimal productSalePrice = (BigDecimal) productCompanyService.get(product, "salePrice", saleOrder.getCompany());
BigDecimal price = (productInAti == resultInAti) ? productSalePrice : this.convertUnitPrice(productInAti, taxLine, productSalePrice);
return currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "saleCurrency", saleOrder.getCompany()), saleOrder.getCurrency(), price, saleOrder.getCreationDate()).setScale(appSaleService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Aggregations