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;
}
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());
}
}
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);
}
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);
}
}
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;
}
Aggregations