use of com.axelor.apps.account.service.FiscalPositionAccountService in project axelor-open-suite by axelor.
the class ContractServiceImpl method generate.
public InvoiceLine generate(Invoice invoice, ContractLine line) throws AxelorException {
BigDecimal inTaxPriceComputed = invoiceLineService.convertUnitPrice(false, line.getTaxLine(), line.getPrice());
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, line.getProduct(), line.getProductName(), line.getPrice(), inTaxPriceComputed, invoice.getInAti() ? inTaxPriceComputed : line.getPrice(), line.getDescription(), line.getQty(), line.getUnit(), line.getTaxLine(), line.getSequence(), BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, line.getExTaxTotal(), line.getInTaxTotal(), false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
InvoiceLine invoiceLine = invoiceLineGenerator.creates().get(0);
FiscalPositionAccountService fiscalPositionAccountService = Beans.get(FiscalPositionAccountService.class);
FiscalPosition fiscalPosition = line.getFiscalPosition();
Account currentAccount = invoiceLine.getAccount();
Account replacedAccount = fiscalPositionAccountService.getAccount(fiscalPosition, currentAccount);
boolean isPurchase = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice) == PriceListRepository.TYPE_PURCHASE;
TaxLine taxLine = Beans.get(AccountManagementService.class).getTaxLine(appBaseService.getTodayDate(invoice.getCompany()), invoiceLine.getProduct(), invoice.getCompany(), fiscalPosition, isPurchase);
invoiceLine.setTaxLine(taxLine);
invoiceLine.setAccount(replacedAccount);
if (line.getAnalyticDistributionTemplate() != null) {
invoiceLine.setAnalyticDistributionTemplate(line.getAnalyticDistributionTemplate());
this.copyAnalyticMoveLines(line.getAnalyticMoveLineList(), invoiceLine);
}
invoice.addInvoiceLineListItem(invoiceLine);
return Beans.get(InvoiceLineRepository.class).save(invoiceLine);
}
Aggregations