use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class OpportunityServiceImpl method setSequence.
@Override
public void setSequence(Opportunity opportunity) throws AxelorException {
Company company = opportunity.getCompany();
String seq = Beans.get(SequenceService.class).getSequenceNumber(SequenceRepository.OPPORTUNITY, company);
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.OPPORTUNITY_1), company != null ? company.getName() : null);
}
opportunity.setOpportunitySeq(seq);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TargetService method createsTargets.
public void createsTargets(TargetConfiguration targetConfiguration) throws AxelorException {
if (targetConfiguration.getPeriodTypeSelect() == TargetConfigurationRepository.PERIOD_TYPE_NONE) {
Target target = this.createTarget(targetConfiguration, targetConfiguration.getFromDate(), targetConfiguration.getToDate());
this.update(target);
} else {
LocalDate oldDate = targetConfiguration.getFromDate();
LocalDate date = oldDate;
while (date.isBefore(targetConfiguration.getToDate()) || date.isEqual(targetConfiguration.getToDate())) {
date = this.getNextDate(targetConfiguration.getPeriodTypeSelect(), date);
Target target2 = targetRepo.all().filter("self.user = ?1 AND self.team = ?2 AND self.periodTypeSelect = ?3 AND self.fromDate >= ?4 AND self.toDate <= ?5 AND " + "((self.callEmittedNumberTarget > 0 AND ?6 > 0) OR (self.meetingNumberTarget > 0 AND ?7 > 0) OR " + "(self.opportunityAmountWonTarget > 0.00 AND ?8 > 0.00) OR (self.opportunityCreatedNumberTarget > 0 AND ?9 > 0) OR (self.opportunityCreatedWonTarget > 0 AND ?10 > 0))", targetConfiguration.getUser(), targetConfiguration.getTeam(), targetConfiguration.getPeriodTypeSelect(), targetConfiguration.getFromDate(), targetConfiguration.getToDate(), targetConfiguration.getCallEmittedNumber(), targetConfiguration.getMeetingNumber(), targetConfiguration.getOpportunityAmountWon().doubleValue(), targetConfiguration.getOpportunityCreatedNumber(), targetConfiguration.getOpportunityCreatedWon()).fetchOne();
if (target2 == null) {
Target target = this.createTarget(targetConfiguration, oldDate, (date.isBefore(targetConfiguration.getToDate())) ? date.minusDays(1) : targetConfiguration.getToDate());
this.update(target);
oldDate = date;
} else {
throw new AxelorException(targetConfiguration, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TARGET_1), target2.getCode(), targetConfiguration.getCode());
}
}
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class BatchEventReminder method generateMessageProcess.
protected void generateMessageProcess() {
MessageRepository messageRepo = Beans.get(MessageRepository.class);
if (!stop) {
int i = 0;
Query q = JPA.em().createQuery(" SELECT er FROM EventReminder as er WHERE er.isReminded = true and ?1 MEMBER OF er.batchSet");
q.setParameter(1, batch);
@SuppressWarnings("unchecked") List<EventReminder> eventReminderList = q.getResultList();
for (EventReminder eventReminder : eventReminderList) {
try {
eventReminder = eventReminderRepo.find(eventReminder.getId());
Message message = messageServiceCrmImpl.createMessage(eventReminder.getEvent());
// Send reminder to owner of the reminder in any case
if (eventReminder.getUser().getPartner() != null && eventReminder.getUser().getPartner().getEmailAddress() != null) {
message.addToEmailAddressSetItem(eventReminder.getUser().getPartner().getEmailAddress());
} else if (eventReminder.getUser().getEmail() != null) {
message.addToEmailAddressSetItem(findOrCreateEmailAddress(eventReminder.getUser().getEmail(), "[" + eventReminder.getUser().getEmail() + "]"));
} else {
messageRepo.remove(message);
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CRM_CONFIG_USER_EMAIL), eventReminder.getUser().getName());
}
// Also send to attendees if needed
if (EventReminderRepository.ASSIGN_TO_ALL.equals(eventReminder.getAssignToSelect()) && eventReminder.getEvent().getAttendees() != null) {
for (ICalendarUser iCalUser : eventReminder.getEvent().getAttendees()) {
if (iCalUser.getUser() != null && iCalUser.getUser().getPartner() != null) {
message.addToEmailAddressSetItem(iCalUser.getUser().getPartner().getEmailAddress());
} else {
message.addToEmailAddressSetItem(findOrCreateEmailAddress(iCalUser.getEmail(), iCalUser.getName()));
}
}
}
message = Beans.get(MessageService.class).sendByEmail(message);
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("Event") + " %s", eventRepo.find(eventReminder.getEvent().getId()).getSubject()), e), ExceptionOriginRepository.CRM, batch.getId());
incrementAnomaly();
LOG.error("Bug(Anomalie) généré(e) pour l'évènement {}", eventRepo.find(eventReminder.getEvent().getId()).getSubject());
} finally {
if (i % 1 == 0) {
JPA.clear();
}
}
}
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method addDetailLines.
@Override
public void addDetailLines(LogisticalForm logisticalForm, StockMove stockMove) throws AxelorException {
Objects.requireNonNull(logisticalForm);
Objects.requireNonNull(stockMove);
if (logisticalForm.getDeliverToCustomerPartner() != null && !logisticalForm.getDeliverToCustomerPartner().equals(stockMove.getPartner())) {
throw new AxelorException(logisticalForm, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.LOGISTICAL_FORM_PARTNER_MISMATCH), logisticalForm.getDeliverToCustomerPartner().getName());
}
if (stockMove.getStockMoveLineList() == null) {
return;
}
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
List<Pair<StockMoveLine, BigDecimal>> toAddList = new ArrayList<>();
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
if (spreadableQty.signum() <= 0) {
continue;
}
if (testForDetailLine(stockMoveLine)) {
toAddList.add(Pair.of(stockMoveLine, spreadableQty));
}
}
if (!toAddList.isEmpty()) {
if (logisticalForm.getLogisticalFormLineList() == null || logisticalForm.getLogisticalFormLineList().isEmpty()) {
addParcelPalletLine(logisticalForm, LogisticalFormLineRepository.TYPE_PARCEL);
}
toAddList.forEach(item -> addDetailLine(logisticalForm, item.getLeft(), item.getRight()));
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method generateStockMove.
public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
StockLocation toStockLocation = stockCorrection.getStockLocation();
Company company = toStockLocation.getCompany();
StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
StockLocationLine stockLocationLine = null;
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
if (stockCorrection.getTrackingNumber() == null) {
stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
} else {
stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
}
BigDecimal realQty = stockCorrection.getRealQty();
Product product = stockCorrection.getProduct();
TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
StockMove stockMove = null;
if (diff.compareTo(BigDecimal.ZERO) == 0) {
return null;
} else if (diff.compareTo(BigDecimal.ZERO) > 0) {
stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
} else {
stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
}
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
stockMove.setOriginId(stockCorrection.getId());
stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
stockMoveService.plan(stockMove);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove, false);
return stockMove;
}
Aggregations