use of com.axelor.apps.supplychain.db.Mrp in project axelor-open-suite by axelor.
the class MrpController method runCalculation.
public void runCalculation(ActionRequest request, ActionResponse response) {
Mrp mrp = request.getContext().asType(Mrp.class);
MrpService mrpService = Beans.get(MrpService.class);
MrpRepository mrpRepository = Beans.get(MrpRepository.class);
try {
mrpService.runCalculation(mrpRepository.find(mrp.getId()));
} catch (Exception e) {
TraceBackService.trace(response, e);
mrpService.onError(mrpRepository.find(mrp.getId()), e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.supplychain.db.Mrp in project axelor-open-suite by axelor.
the class MrpController method printWeeks.
/**
* Prints the weekly breakdown MRP birt report and shows it to the user.
*
* @param request
* @param response
*/
public void printWeeks(ActionRequest request, ActionResponse response) {
Mrp mrp = request.getContext().asType(Mrp.class);
mrp = Beans.get(MrpRepository.class).find(mrp.getId());
String name = I18n.get("MRP") + "-" + mrp.getId();
try {
String fileLink = ReportFactory.createReport(IReport.MRP_WEEKS, name).addParam("mrpId", mrp.getId()).addParam("Timezone", getTimezone(mrp)).addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("endDate", Beans.get(MrpService.class).findMrpEndDate(mrp).atStartOfDay().toString()).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
response.setView(ActionView.define(name).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.db.Mrp in project axelor-open-suite by axelor.
the class MrpController method printList.
/**
* Prints the list MRP birt report and shows it to the user.
*
* @param request
* @param response
*/
public void printList(ActionRequest request, ActionResponse response) {
Mrp mrp = request.getContext().asType(Mrp.class);
String name = I18n.get("MRP") + "-" + mrp.getId();
try {
String fileLink = ReportFactory.createReport(IReport.MRP_LIST, name).addParam("mrpId", mrp.getId()).addParam("Timezone", getTimezone(mrp)).addParam("Locale", ReportSettings.getPrintingLocale(null)).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
response.setView(ActionView.define(name).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.supplychain.db.Mrp in project axelor-open-suite by axelor.
the class ProjectedStockServiceImpl method createProjectedStock.
@Transactional(rollbackOn = { Exception.class })
@Override
public List<MrpLine> createProjectedStock(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
Product product = Beans.get(ProductRepository.class).find(productId);
Company company = Beans.get(CompanyRepository.class).find(companyId);
StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
Mrp mrp = new Mrp();
mrp.setStockLocation(findStockLocation(company, stockLocation));
// If a company has no stockLocation
if (mrp.getStockLocation() == null) {
return Collections.emptyList();
}
mrp.addProductSetItem(product);
mrp.setMrpTypeSelect(MrpRepository.MRP_TYPE_MRP);
mrp = Beans.get(MrpRepository.class).save(mrp);
mrp = Beans.get(MrpService.class).createProjectedStock(mrp, product, company, stockLocation);
List<MrpLine> mrpLineList = Beans.get(MrpLineRepository.class).all().filter("self.mrp = ?1 AND self.product = ?2 AND self.qty != 0", mrp, product).order("maturityDate").order("mrpLineType.typeSelect").order("mrpLineType.sequence").order("id").fetch();
if (mrpLineList.isEmpty()) {
List<MrpLine> mrpLineListToDelete = Beans.get(MrpLineRepository.class).all().filter("self.mrp = ?1", mrp).fetch();
removeMrpAndMrpLine(mrpLineListToDelete);
return Collections.emptyList();
}
for (MrpLine mrpLine : mrpLineList) {
mrpLine.setCompany(mrpLine.getStockLocation().getCompany());
mrpLine.setUnit(mrpLine.getProduct().getUnit());
}
return mrpLineList;
}
use of com.axelor.apps.supplychain.db.Mrp in project axelor-open-suite by axelor.
the class MrpController method generateAllProposals.
public void generateAllProposals(ActionRequest request, ActionResponse response) {
try {
Mrp mrp = request.getContext().asType(Mrp.class);
Boolean isProposalsPerSupplier = (Boolean) request.getContext().get("consolidateProposalsPerSupplier");
Beans.get(MrpService.class).generateProposals(Beans.get(MrpRepository.class).find(mrp.getId()), isProposalsPerSupplier != null && isProposalsPerSupplier);
response.setFlash(I18n.get("Proposals have been generated successfully."));
} catch (AxelorException e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
Aggregations