Search in sources :

Example 1 with AccountManagementAccountService

use of com.axelor.apps.account.service.AccountManagementAccountService in project axelor-open-suite by axelor.

the class IntercoServiceImpl method createIntercoInvoiceLine.

protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    Invoice intercoInvoice = invoiceLine.getInvoice();
    Partner partner = intercoInvoice.getPartner();
    if (intercoInvoice.getCompany() != null) {
        Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
        invoiceLine.setAccount(account);
        TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
        invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
        invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
        if (invoiceLine.getAnalyticDistributionTemplate() != null) {
            invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
            List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
            analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
            invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
        }
    }
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Invoice(com.axelor.apps.account.db.Invoice) AccountManagementAccountService(com.axelor.apps.account.service.AccountManagementAccountService) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Aggregations

Account (com.axelor.apps.account.db.Account)1 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)1 Invoice (com.axelor.apps.account.db.Invoice)1 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)1 TaxLine (com.axelor.apps.account.db.TaxLine)1 AccountManagementAccountService (com.axelor.apps.account.service.AccountManagementAccountService)1 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)1 Partner (com.axelor.apps.base.db.Partner)1