Search in sources :

Example 26 with AxelorException

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) SequenceService(com.axelor.apps.base.service.administration.SequenceService)

Example 27 with AxelorException

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());
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Target(com.axelor.apps.crm.db.Target) LocalDate(java.time.LocalDate)

Example 28 with AxelorException

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();
                }
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) EventReminder(com.axelor.apps.crm.db.EventReminder) Query(javax.persistence.Query) IExceptionMessage(com.axelor.apps.crm.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) MessageRepository(com.axelor.apps.message.db.repo.MessageRepository) AxelorException(com.axelor.exception.AxelorException)

Example 29 with AxelorException

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()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair)

Example 30 with AxelorException

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27