Search in sources :

Example 1 with MrpLine

use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.

the class MrpLineServiceImpl method createMrpLine.

public MrpLine createMrpLine(Mrp mrp, Product product, int maxLevel, MrpLineType mrpLineType, BigDecimal qty, LocalDate maturityDate, BigDecimal cumulativeQty, StockLocation stockLocation, Model model) {
    MrpLine mrpLine = new MrpLine();
    mrpLine.setMrp(mrp);
    mrpLine.setProduct(product);
    mrpLine.setMaxLevel(maxLevel);
    mrpLine.setMrpLineType(mrpLineType);
    if (mrpLineType.getTypeSelect() == MrpLineTypeRepository.TYPE_OUT) {
        mrpLine.setQty(qty.negate());
    } else {
        mrpLine.setQty(qty);
    }
    mrpLine.setMaturityDate(maturityDate);
    mrpLine.setCumulativeQty(cumulativeQty);
    mrpLine.setStockLocation(stockLocation);
    mrpLine = this.setMrpLineQty(mrpLine, product, stockLocation);
    if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_PURCHASE_PROPOSAL) {
        mrpLine.setSupplierPartner(product.getDefaultSupplierPartner());
    }
    this.updatePartner(mrpLine, model);
    this.createMrpLineOrigins(mrpLine, model);
    log.debug("Create mrp line for the product {}, level {}, mrpLineType {}, qty {}, maturity date {}, cumulative qty {}, stock location {}, related to {}", product.getCode(), maxLevel, mrpLineType.getCode(), qty, maturityDate, cumulativeQty, stockLocation.getName(), mrpLine.getRelatedToSelectName());
    return mrpLine;
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine)

Example 2 with MrpLine

use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.

the class MrpServiceImpl method computeCumulativeQty.

@Transactional
protected void computeCumulativeQty(Product product) {
    List<MrpLine> mrpLineList = mrpLineRepository.all().filter("self.mrp.id = ?1 AND self.product.id = ?2", mrp.getId(), product.getId()).order("maturityDate").order("mrpLineType.typeSelect").order("mrpLineType.sequence").order("id").fetch();
    BigDecimal previousCumulativeQty = BigDecimal.ZERO;
    for (MrpLine mrpLine : mrpLineList) {
        mrpLine.setCumulativeQty(previousCumulativeQty.add(mrpLine.getQty()));
        previousCumulativeQty = mrpLine.getCumulativeQty();
        log.debug("Cumulative qty is ({}) for product ({}) and move ({}) at the maturity date ({})", previousCumulativeQty, mrpLine.getProduct().getFullName(), mrpLine.getMrpLineType().getName(), mrpLine.getMaturityDate());
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 3 with MrpLine

use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.

the class MrpServiceImpl method createProposalMrpLine.

@Transactional(rollbackOn = { Exception.class })
protected void createProposalMrpLine(Mrp mrp, Product product, MrpLineType mrpLineType, BigDecimal reorderQty, StockLocation stockLocation, LocalDate maturityDate, List<MrpLineOrigin> mrpLineOriginList, String relatedToSelectName) throws AxelorException {
    LocalDate initialMaturityDate = maturityDate;
    if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_PURCHASE_PROPOSAL) {
        maturityDate = maturityDate.minusDays(product.getSupplierDeliveryTime());
        reorderQty = reorderQty.max(this.getSupplierCatalogMinQty(product));
        if (appPurchaseService.getAppPurchase() != null && appPurchaseService.getAppPurchase().getManageMultiplePurchaseQuantity()) {
            reorderQty = computeMultipleProductsPurchaseReorderQty(product, reorderQty);
        }
    }
    if (maturityDate.isBefore(today)) {
        maturityDate = today;
    }
    MrpLine mrpLine = this.getPreviousProposalMrpLine(product, mrpLineType, stockLocation, maturityDate);
    if (mrpLine != null) {
        if (mrpLineType.getTypeSelect() == MrpLineTypeRepository.TYPE_OUT) {
            reorderQty = reorderQty.negate();
        }
        mrpLine.setQty(mrpLine.getQty().add(reorderQty));
        mrpLine.setRelatedToSelectName(null);
    } else {
        MrpLine createdmrpLine = this.createMrpLine(mrp, product, mrpLineType, reorderQty, maturityDate, BigDecimal.ZERO, stockLocation, null);
        if (createdmrpLine != null) {
            createdmrpLine.setWarnDelayFromSupplier(getWarnDelayFromSupplier(createdmrpLine, initialMaturityDate));
            mrpLine = mrpLineRepository.save(createdmrpLine);
        }
        mrpLine.setRelatedToSelectName(relatedToSelectName);
    }
    this.copyMrpLineOrigins(mrpLine, mrpLineOriginList);
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 4 with MrpLine

use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.

the class ProjectedStockController method showProjectedStock.

public void showProjectedStock(ActionRequest request, ActionResponse response) {
    try {
        ProjectedStockService projectedStockService = Beans.get(ProjectedStockService.class);
        Map<String, Long> mapId = projectedStockService.getProductIdCompanyIdStockLocationIdFromContext(request.getContext());
        if (mapId == null || mapId.get("productId") == 0L) {
            return;
        }
        final List<MrpLine> mrpLineList = new ArrayList<>();
        try {
            mrpLineList.addAll(projectedStockService.createProjectedStock(mapId.get("productId"), mapId.get("companyId"), mapId.get("stockLocationId")));
            response.setView(ActionView.define(I18n.get("Projected stock")).model(MrpLine.class.getName()).add("form", "projected-stock-form").param("popup", "true").param("popup-save", "false").param("popup.maximized", "true").context("_mrpLineList", mrpLineList).map());
        } catch (Exception e) {
            TraceBackService.trace(response, e);
        } finally {
            projectedStockService.removeMrpAndMrpLine(mrpLineList);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) ArrayList(java.util.ArrayList) MrpLine(com.axelor.apps.supplychain.db.MrpLine)

Example 5 with MrpLine

use of com.axelor.apps.supplychain.db.MrpLine in project axelor-open-suite by axelor.

the class MrpLineManagementRepository method populate.

/**
 * set alert if purchase delivery date is to far from proposal
 */
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long mrpLineId = (Long) json.get("id");
    MrpLine mrpLine = find(mrpLineId);
    Map<String, Object> mrpLineMap = super.populate(json, context);
    if (PurchaseOrder.class.getName().equals(mrpLine.getProposalSelect())) {
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(mrpLine.getProposalSelectId());
        mrpLine.setIsOutDayNbBetweenPurchaseAndProposal(mrpLine.getProduct() != null && mrpLine.getMaturityDate() != null && (purchaseOrder.getDeliveryDate() == null || mrpLine.getProduct().getMrpFamily() == null || Math.abs(mrpLine.getMaturityDate().toEpochDay() - purchaseOrder.getDeliveryDate().toEpochDay()) > mrpLine.getProduct().getMrpFamily().getDayNbBetweenPurchaseAndProposal()));
        json.put("isOutDayNbBetweenPurchaseAndProposal", mrpLine.getIsOutDayNbBetweenPurchaseAndProposal());
    }
    return mrpLineMap;
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository)

Aggregations

MrpLine (com.axelor.apps.supplychain.db.MrpLine)19 Transactional (com.google.inject.persist.Transactional)10 LocalDate (java.time.LocalDate)6 BigDecimal (java.math.BigDecimal)4 Product (com.axelor.apps.base.db.Product)3 Unit (com.axelor.apps.base.db.Unit)3 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)3 ArrayList (java.util.ArrayList)3 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)2 StockLocation (com.axelor.apps.stock.db.StockLocation)2 MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)2 MrpLineService (com.axelor.apps.supplychain.service.MrpLineService)2 ProjectedStockService (com.axelor.apps.supplychain.service.ProjectedStockService)2 AxelorException (com.axelor.exception.AxelorException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 OperationOrder (com.axelor.apps.production.db.OperationOrder)1