Search in sources :

Example 1 with FiscalPosition

use of com.axelor.apps.account.db.FiscalPosition in project axelor-open-suite by axelor.

the class SaleOrderLineServiceImpl method fillTaxInformation.

protected void fillTaxInformation(SaleOrderLine saleOrderLine, SaleOrder saleOrder) throws AxelorException {
    if (saleOrder.getClientPartner() != null) {
        TaxLine taxLine = this.getTaxLine(saleOrder, saleOrderLine);
        saleOrderLine.setTaxLine(taxLine);
        FiscalPosition fiscalPosition = saleOrder.getClientPartner().getFiscalPosition();
        TaxEquiv taxEquiv = accountManagementService.getProductTaxEquiv(saleOrderLine.getProduct(), saleOrder.getCompany(), fiscalPosition, false);
        saleOrderLine.setTaxEquiv(taxEquiv);
    } else {
        saleOrderLine.setTaxLine(null);
        saleOrderLine.setTaxEquiv(null);
    }
}
Also used : FiscalPosition(com.axelor.apps.account.db.FiscalPosition) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 2 with FiscalPosition

use of com.axelor.apps.account.db.FiscalPosition 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);
}
Also used : FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) Account(com.axelor.apps.account.db.Account) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 3 with FiscalPosition

use of com.axelor.apps.account.db.FiscalPosition in project axelor-open-suite by axelor.

the class InvoiceLineServiceImpl method fillPriceAndAccount.

@Override
public Map<String, Object> fillPriceAndAccount(Invoice invoice, InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    Map<String, Object> productInformation = resetProductInformation(invoice);
    Product product = invoiceLine.getProduct();
    TaxLine taxLine = null;
    Company company = invoice.getCompany();
    FiscalPosition fiscalPosition = invoice.getPartner().getFiscalPosition();
    try {
        taxLine = this.getTaxLine(invoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        productInformation.put("taxLine", taxLine);
        productInformation.put("taxRate", taxLine.getValue());
        productInformation.put("taxCode", taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(product, company, fiscalPosition, isPurchase);
        productInformation.put("taxEquiv", taxEquiv);
        Account account = accountManagementAccountService.getProductAccount(product, company, fiscalPosition, isPurchase, invoiceLine.getFixedAssets());
        productInformation.put("account", account);
    } catch (AxelorException e) {
        productInformation.put("error", e.getMessage());
    }
    BigDecimal price = this.getExTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    BigDecimal inTaxPrice = this.getInTaxUnitPrice(invoice, invoiceLine, taxLine, isPurchase);
    productInformation.put("price", price);
    productInformation.put("inTaxPrice", inTaxPrice);
    productInformation.putAll(this.getDiscount(invoice, invoiceLine, product.getInAti() ? inTaxPrice : price));
    productInformation.put("productName", invoiceLine.getProduct().getName());
    return productInformation;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) Product(com.axelor.apps.base.db.Product) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Aggregations

FiscalPosition (com.axelor.apps.account.db.FiscalPosition)3 TaxLine (com.axelor.apps.account.db.TaxLine)3 Account (com.axelor.apps.account.db.Account)2 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)2 BigDecimal (java.math.BigDecimal)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 InvoiceLineRepository (com.axelor.apps.account.db.repo.InvoiceLineRepository)1 FiscalPositionAccountService (com.axelor.apps.account.service.FiscalPositionAccountService)1 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)1 Company (com.axelor.apps.base.db.Company)1 Product (com.axelor.apps.base.db.Product)1 AccountManagementService (com.axelor.apps.base.service.tax.AccountManagementService)1 AxelorException (com.axelor.exception.AxelorException)1 ArrayList (java.util.ArrayList)1