use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method checkStockMax.
protected void checkStockMax(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type, BigDecimal baseQty) throws AxelorException {
StockLocation stockLocation = stockLocationLine.getStockLocation();
StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
if (stockRules == null || !stockRules.getUseMaxQty()) {
return;
}
if (baseQty.add(qty).compareTo(stockRules.getMaxQty()) > 0) {
throw new AxelorException(stockLocationLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_3), stockLocationLine.getProduct().getName(), stockLocationLine.getProduct().getCode());
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class InventoryManagementRepository method save.
@Override
public Inventory save(Inventory entity) {
Inventory inventory = super.save(entity);
SequenceService sequenceService = Beans.get(SequenceService.class);
try {
if (Strings.isNullOrEmpty(inventory.getInventorySeq())) {
inventory.setInventorySeq(sequenceService.getDraftSequenceNumber(inventory));
}
} catch (AxelorException e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
entity.setInventoryTitle(Beans.get(InventoryService.class).computeTitle(entity));
return inventory;
}
use of com.axelor.exception.AxelorException 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.exception.AxelorException in project axelor-open-suite by axelor.
the class SaleOrderPrintServiceImpl method prepareReportSettings.
@Override
public ReportSettings prepareReportSettings(SaleOrder saleOrder, boolean proforma, String format) throws AxelorException {
if (saleOrder.getPrintingSettings() == null) {
if (saleOrder.getCompany().getPrintingSettings() != null) {
saleOrder.setPrintingSettings(saleOrder.getCompany().getPrintingSettings());
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.SALE_ORDER_MISSING_PRINTING_SETTINGS), saleOrder.getSaleOrderSeq()), saleOrder);
}
}
String locale = ReportSettings.getPrintingLocale(saleOrder.getClientPartner());
String title = saleOrderService.getFileName(saleOrder);
ReportSettings reportSetting = ReportFactory.createReport(IReport.SALES_ORDER, title + " - ${date}");
return reportSetting.addParam("SaleOrderId", saleOrder.getId()).addParam("Timezone", saleOrder.getCompany() != null ? saleOrder.getCompany().getTimezone() : null).addParam("Locale", locale).addParam("ProformaInvoice", proforma).addParam("HeaderHeight", saleOrder.getPrintingSettings().getPdfHeaderHeight()).addParam("FooterHeight", saleOrder.getPrintingSettings().getPdfFooterHeight()).addFormat(format);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class InvoiceGenerator method createInvoiceHeader.
protected Invoice createInvoiceHeader() throws AxelorException {
Invoice invoice = new Invoice();
invoice.setCompany(company);
invoice.setOperationTypeSelect(operationType);
if (partner == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
if (Beans.get(BlockingService.class).getBlocking(partner, company, BlockingRepository.INVOICING_BLOCKING) != null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.INVOICE_VALIDATE_BLOCKING));
}
invoice.setPartner(partner);
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation != null) {
invoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
invoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
invoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
}
if (paymentCondition == null) {
paymentCondition = InvoiceToolService.getPaymentCondition(invoice);
}
invoice.setPaymentCondition(paymentCondition);
if (paymentMode == null) {
paymentMode = InvoiceToolService.getPaymentMode(invoice);
}
invoice.setPaymentMode(paymentMode);
if (mainInvoicingAddress == null) {
mainInvoicingAddress = Beans.get(PartnerService.class).getInvoicingAddress(partner);
}
invoice.setAddress(mainInvoicingAddress);
invoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(invoice.getAddress()));
invoice.setContactPartner(contactPartner);
if (currency == null) {
currency = partner.getCurrency();
}
if (currency == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_6), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
invoice.setCurrency(currency);
invoice.setStatusSelect(InvoiceRepository.STATUS_DRAFT);
invoice.setPriceList(priceList);
invoice.setInternalReference(internalReference);
invoice.setExternalReference(externalReference);
invoice.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, company));
invoice.setTradingName(tradingName);
if (groupProductsOnPrintings == null) {
groupProductsOnPrintings = partner.getGroupProductsOnPrintings();
}
invoice.setGroupProductsOnPrintings(groupProductsOnPrintings);
// Set ATI mode on invoice
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
int atiChoice = accountConfig.getInvoiceInAtiSelect();
if (inAti == null) {
invoice.setInAti(accountConfigService.getInvoiceInAti(accountConfig));
} else if (atiChoice == AccountConfigRepository.INVOICE_ATI_DEFAULT || atiChoice == AccountConfigRepository.INVOICE_WT_DEFAULT) {
invoice.setInAti(inAti);
} else if (atiChoice == AccountConfigRepository.INVOICE_ATI_ALWAYS) {
invoice.setInAti(true);
} else {
invoice.setInAti(false);
}
if (partner.getFactorizedCustomer() && accountConfig.getFactorPartner() != null) {
List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
companyBankDetails = bankDetailsList.stream().filter(bankDetails -> bankDetails.getIsDefault()).findFirst().orElse(null);
} else if (accountingSituation != null) {
if (paymentMode != null) {
if (paymentMode.equals(partner.getOutPaymentMode())) {
companyBankDetails = accountingSituation.getCompanyOutBankDetails();
} else if (paymentMode.equals(partner.getInPaymentMode())) {
companyBankDetails = accountingSituation.getCompanyInBankDetails();
}
}
}
if (companyBankDetails == null) {
companyBankDetails = company.getDefaultBankDetails();
List<BankDetails> allowedBDs = Beans.get(PaymentModeService.class).getCompatibleBankDetailsList(paymentMode, company);
if (!allowedBDs.contains(companyBankDetails)) {
companyBankDetails = null;
}
}
invoice.setCompanyBankDetails(companyBankDetails);
if (partner.getBankDetailsList() != null && invoice.getBankDetails() == null) {
invoice.setBankDetails(partner.getBankDetailsList().stream().filter(b -> b.getActive() && b.getIsDefault()).findFirst().orElse(null));
}
if (partner != null && !Strings.isNullOrEmpty(partner.getInvoiceComments())) {
invoice.setNote(partner.getInvoiceComments());
}
invoice.setInvoicesCopySelect(getInvoiceCopy());
initCollections(invoice);
return invoice;
}
Aggregations