Search in sources :

Example 41 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ExpenseServiceImpl method createInvoiceLine.

@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, ExpenseLine expenseLine, int priority) throws AxelorException {
    Product product = expenseLine.getExpenseProduct();
    InvoiceLineGenerator invoiceLineGenerator = null;
    Integer atiChoice = invoice.getCompany().getAccountConfig().getInvoiceInAtiSelect();
    if (atiChoice == AccountConfigRepository.INVOICE_WT_ALWAYS || atiChoice == AccountConfigRepository.INVOICE_WT_DEFAULT) {
        invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, product.getName(), expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), expenseLine.getUntaxedAmount(), expenseLine.getComments(), BigDecimal.ONE, product.getUnit(), null, priority, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), false) {

            @Override
            public List<InvoiceLine> creates() throws AxelorException {
                InvoiceLine invoiceLine = this.createInvoiceLine();
                List<InvoiceLine> invoiceLines = new ArrayList<>();
                invoiceLines.add(invoiceLine);
                return invoiceLines;
            }
        };
    } else {
        invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, product.getName(), expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), expenseLine.getTotalAmount(), expenseLine.getComments(), BigDecimal.ONE, product.getUnit(), null, priority, BigDecimal.ZERO, PriceListLineRepository.AMOUNT_TYPE_NONE, expenseLine.getUntaxedAmount(), expenseLine.getTotalAmount(), false) {

            @Override
            public List<InvoiceLine> creates() throws AxelorException {
                InvoiceLine invoiceLine = this.createInvoiceLine();
                List<InvoiceLine> invoiceLines = new ArrayList<>();
                invoiceLines.add(invoiceLine);
                return invoiceLines;
            }
        };
    }
    return invoiceLineGenerator.creates();
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Product(com.axelor.apps.base.db.Product) List(java.util.List) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)

Example 42 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method allocateReservedQuantityInSaleOrderLines.

/**
 * The new parameter allocated stock move line is used if we are allocating a stock move line.
 * This method will reallocate the lines with the same stock move (and the same product) before
 * other stock move lines.
 *
 * <p>We are using an optional because in the basic use of the method, the argument is empty.
 */
protected BigDecimal allocateReservedQuantityInSaleOrderLines(BigDecimal qtyToAllocate, StockLocation stockLocation, Product product, Unit stockLocationLineUnit, Optional<StockMoveLine> allocatedStockMoveLine) throws AxelorException {
    List<StockMoveLine> stockMoveLineListToAllocate = stockMoveLineRepository.all().filter("self.stockMove.fromStockLocation.id = :stockLocationId " + "AND self.product.id = :productId " + "AND self.stockMove.statusSelect = :planned " + "AND self.reservationDateTime IS NOT NULL " + "AND self.reservedQty < self.requestedReservedQty").bind("stockLocationId", stockLocation.getId()).bind("productId", product.getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).order("reservationDateTime").order("stockMove.estimatedDate").fetch();
    // put stock move lines with the same stock move on the beginning of the list.
    allocatedStockMoveLine.ifPresent(stockMoveLine -> stockMoveLineListToAllocate.sort(// Note: this comparator imposes orderings that are inconsistent with equals.
    (sml1, sml2) -> {
        if (sml1.getStockMove().equals(sml2.getStockMove())) {
            return 0;
        } else if (sml1.getStockMove().equals(stockMoveLine.getStockMove())) {
            return -1;
        } else if (sml2.getStockMove().equals(stockMoveLine.getStockMove())) {
            return 1;
        } else {
            return 0;
        }
    }));
    BigDecimal leftQtyToAllocate = qtyToAllocate;
    for (StockMoveLine stockMoveLine : stockMoveLineListToAllocate) {
        BigDecimal leftQtyToAllocateStockMove = convertUnitWithProduct(stockLocationLineUnit, stockMoveLine.getUnit(), leftQtyToAllocate, product);
        BigDecimal neededQtyToAllocate = stockMoveLine.getRequestedReservedQty().subtract(stockMoveLine.getReservedQty());
        BigDecimal allocatedStockMoveQty = leftQtyToAllocateStockMove.min(neededQtyToAllocate);
        BigDecimal allocatedQty = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLineUnit, allocatedStockMoveQty, product);
        // update reserved qty in stock move line and sale order line
        updateReservedQuantityFromStockMoveLine(stockMoveLine, product, allocatedStockMoveQty);
        // update left qty to allocate
        leftQtyToAllocate = leftQtyToAllocate.subtract(allocatedQty);
    }
    return qtyToAllocate.subtract(leftQtyToAllocate);
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) Inject(com.google.inject.Inject) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Comparator(java.util.Comparator) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 43 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method changeRequestedQtyLowerThanQty.

/**
 * On planning, we want the requested quantity to be equal or lower to the quantity of the line.
 * So, if the requested quantity is greater than the quantity, we change it to be equal.
 *
 * @param stockMoveLine
 * @throws AxelorException
 */
protected void changeRequestedQtyLowerThanQty(StockMoveLine stockMoveLine) throws AxelorException {
    BigDecimal qty = stockMoveLine.getRealQty().max(BigDecimal.ZERO);
    BigDecimal requestedReservedQty = stockMoveLine.getRequestedReservedQty();
    if (requestedReservedQty.compareTo(qty) > 0) {
        Product product = stockMoveLine.getProduct();
        BigDecimal diffRequestedQty = requestedReservedQty.subtract(qty);
        stockMoveLine.setRequestedReservedQty(qty);
        // update in stock location line
        StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), product);
        BigDecimal diffRequestedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffRequestedQty, product);
        stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffRequestedQuantityLocation));
    }
}
Also used : Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 44 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class SaleOrderInvoiceServiceImpl method generateAdvancePayment.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateAdvancePayment(SaleOrder saleOrder, BigDecimal amountToInvoice, boolean isPercent) throws AxelorException {
    List<SaleOrderLineTax> taxLineList = saleOrder.getSaleOrderLineTaxList();
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    BigDecimal percentToInvoice = computeAmountToInvoicePercent(saleOrder, amountToInvoice, isPercent);
    Product invoicingProduct = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentProduct();
    Account advancePaymentAccount = accountConfigService.getAccountConfig(saleOrder.getCompany()).getAdvancePaymentAccount();
    if (invoicingProduct == null) {
        throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_PRODUCT));
    }
    if (advancePaymentAccount == null) {
        throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_MISSING_ADVANCE_PAYMENT_ACCOUNT), saleOrder.getCompany().getName());
    }
    Invoice invoice = createInvoiceAndLines(saleOrder, taxLineList, invoicingProduct, percentToInvoice, InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE, advancePaymentAccount);
    // no need for link to sale order lines for an advance payment
    if (invoice.getInvoiceLineList() != null) {
        invoice.getInvoiceLineList().forEach(invoiceLine -> invoiceLine.setSaleOrderLine(null));
    }
    return invoiceRepo.save(invoice);
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Invoice(com.axelor.apps.account.db.Invoice) SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 45 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class MrpServiceImpl method computeMultipleProductsPurchaseReorderQty.

protected BigDecimal computeMultipleProductsPurchaseReorderQty(Product product, BigDecimal reorderQty) {
    List<ProductMultipleQty> productMultipleQtyList = product.getPurchaseProductMultipleQtyList();
    if (productMultipleQtyList == null || reorderQty == null || reorderQty.signum() == 0) {
        return reorderQty;
    }
    BigDecimal diff = productMultipleQtyList.stream().map(ProductMultipleQty::getMultipleQty).filter(bigDecimal -> bigDecimal.signum() != 0).map(bigDecimal -> {
        BigDecimal remainder = reorderQty.remainder(bigDecimal);
        return remainder.signum() == 0 ? BigDecimal.ZERO : bigDecimal.subtract(remainder);
    }).min(Comparator.naturalOrder()).orElse(BigDecimal.ZERO);
    return reorderQty.add(diff);
}
Also used : ProductMultipleQty(com.axelor.apps.base.db.ProductMultipleQty) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) MrpLineTypeRepository(com.axelor.apps.supplychain.db.repo.MrpLineTypeRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) MrpLineOrigin(com.axelor.apps.supplychain.db.MrpLineOrigin) AppPurchaseService(com.axelor.apps.purchase.service.app.AppPurchaseService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Transactional(com.google.inject.persist.Transactional) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockRulesRepository(com.axelor.apps.stock.db.repo.StockRulesRepository) StockRules(com.axelor.apps.stock.db.StockRules) StockLocationService(com.axelor.apps.stock.service.StockLocationService) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) MrpLine(com.axelor.apps.supplychain.db.MrpLine) MethodHandles(java.lang.invoke.MethodHandles) ProductMultipleQty(com.axelor.apps.base.db.ProductMultipleQty) MrpFamily(com.axelor.apps.supplychain.db.MrpFamily) Set(java.util.Set) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) SupplierCatalog(com.axelor.apps.purchase.db.SupplierCatalog) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Product(com.axelor.apps.base.db.Product) Mrp(com.axelor.apps.supplychain.db.Mrp) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Partner(com.axelor.apps.base.db.Partner) Company(com.axelor.apps.base.db.Company) Query(com.axelor.db.Query) AbstractBatch(com.axelor.apps.base.service.administration.AbstractBatch) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) ArrayList(java.util.ArrayList) MrpLineRepository(com.axelor.apps.supplychain.db.repo.MrpLineRepository) Lists(com.google.common.collect.Lists) MrpRepository(com.axelor.apps.supplychain.db.repo.MrpRepository) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) Maps(com.google.common.collect.Maps) DAYS(java.time.temporal.ChronoUnit.DAYS) StockRulesService(com.axelor.apps.stock.service.StockRulesService) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) Comparator(java.util.Comparator) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16