Search in sources :

Example 1 with ProductMultipleQty

use of com.axelor.apps.base.db.ProductMultipleQty 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

Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 Product (com.axelor.apps.base.db.Product)1 ProductMultipleQty (com.axelor.apps.base.db.ProductMultipleQty)1 Unit (com.axelor.apps.base.db.Unit)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 AbstractBatch (com.axelor.apps.base.service.administration.AbstractBatch)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SupplierCatalog (com.axelor.apps.purchase.db.SupplierCatalog)1 PurchaseOrderLineRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository)1 PurchaseOrderRepository (com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)1 AppPurchaseService (com.axelor.apps.purchase.service.app.AppPurchaseService)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1