use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class LogisticalFormStockRepository method save.
@Override
public LogisticalForm save(LogisticalForm logisticalForm) {
try {
Company company = logisticalForm.getCompany();
if (company != null) {
if (Strings.isNullOrEmpty(logisticalForm.getDeliveryNumberSeq())) {
String sequenceNumber = Beans.get(SequenceService.class).getSequenceNumber("logisticalForm", logisticalForm.getCompany());
if (Strings.isNullOrEmpty(sequenceNumber)) {
throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_SEQUENCE), logisticalForm.getCompany().getName());
}
logisticalForm.setDeliveryNumberSeq(sequenceNumber);
}
if (!logisticalForm.getIsEmailSent()) {
StockConfig stockConfig = Beans.get(StockConfigService.class).getStockConfig(company);
if (stockConfig.getLogisticalFormAutomaticEmail()) {
Template template = stockConfig.getLogisticalFormMessageTemplate();
if (template == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_TEMPLATE), logisticalForm);
}
Beans.get(TemplateMessageService.class).generateAndSendMessage(logisticalForm, template);
logisticalForm.setIsEmailSent(true);
}
}
}
return super.save(logisticalForm);
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
}
use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method sendCancellationEmail.
@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendCancellationEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
Template template = hrConfig.getCanceledTimesheetTemplate();
if (hrConfig.getTimesheetMailNotification() && template != null) {
return templateMessageService.generateAndSendMessage(timesheet, template);
}
return null;
}
use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class ActionEmailBuilderService method sendEmail.
@CallMethod
public ActionResponse sendEmail(Long objectId, String model, String tag, Long templateId, int sendOption) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
Template template = templateRepo.find(templateId);
Message message = templateMessageService.generateMessage(objectId, model, tag, template);
ActionResponse response = new ActionResponse();
if (sendOption == 0) {
messageService.sendByEmail(message);
} else {
response.setView(ActionView.define(I18n.get(IExceptionMessage.MESSAGE_3)).model(Message.class.getName()).add("form", "message-form").param("forceEdit", "true").context("_showRecord", message.getId().toString()).map());
}
return response;
}
use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class ActionEmailBuilderService method build.
public MetaAction build(ActionBuilder builder) {
String name = builder.getName();
Object model = builder.getIsJson() ? metaJsonModelRepo.all().filter("self.name = ?", builder.getModel()).fetchOne() : metaModelRepo.all().filter("self.fullName = ?", builder.getModel()).fetchOne();
int sendOption = builder.getEmailSendOptionSelect();
Template template = builder.getEmailTemplate();
String xml = "<action-method name=\"" + name + "\" id=\"" + builder.getXmlId() + "\">\n\t" + "<call class=\"com.axelor.studio.service.builder.ActionEmailBuilderService\" method=\"sendEmail(id, '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getFullName()) + "', '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getName()) + "', '" + template.getId() + "', '" + sendOption + "')\" " + "if=\"id != null\"/>\n" + "</action-method>";
return studioMetaService.updateMetaAction(name, "action-method", xml, null, builder.getXmlId());
}
use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class BatchTimesheetReminder method process.
@Override
protected void process() {
Template template = batch.getHrBatch().getTemplate();
MetaModel metaModel = template.getMetaModel();
try {
if (metaModel != null) {
if (metaModel.getName().equals(Employee.class.getSimpleName())) {
sendReminderUsingEmployees(template);
} else if (metaModel.getName().equals(Timesheet.class.getSimpleName())) {
sendReminderUsingTimesheets(template);
}
}
} catch (Exception e) {
TraceBackService.trace(e, metaModel.getName(), batch.getId());
incrementAnomaly();
}
}
Aggregations