use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class PrintTemplateServiceImpl method initMaker.
@SuppressWarnings("unchecked")
protected TemplateMaker initMaker(Long objectId, String model, String simpleModel, Locale locale) throws ClassNotFoundException {
String timezone = null;
Company activeCompany = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
if (activeCompany != null) {
timezone = activeCompany.getTimezone();
}
TemplateMaker maker = new TemplateMaker(timezone, locale, TEMPLATE_DELIMITER, TEMPLATE_DELIMITER);
Class<? extends Model> myClass = (Class<? extends Model>) Class.forName(model);
maker.setContext(JPA.find(myClass, objectId), simpleModel);
return maker;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class BatchCalendarSynchronization method process.
@Override
protected void process() {
final Company company = batch.getBaseBatch().getCompany();
;
final List<ICalendar> calendars = repo.all().filter("self.user.activeCompany = :company AND self.isValid = TRUE").bind("company", company).fetch();
for (ICalendar calendar : calendars) {
try {
iCalendarService.sync(calendar, batch.getBaseBatch().getAllEvents(), batch.getBaseBatch().getSynchronizationDuration());
incrementDone();
} catch (Exception e) {
e.printStackTrace();
incrementAnomaly();
}
}
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class ConvertLeadWizardController method setConvertLeadIntoOpportunity.
public void setConvertLeadIntoOpportunity(ActionRequest request, ActionResponse response) throws AxelorException {
Lead lead = findLead(request);
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
response.setAttr("lead", "value", lead);
response.setAttr("amount", "value", lead.getEstimatedBudget());
response.setAttr("customerDescription", "value", lead.getDescription());
response.setAttr("source", "value", lead.getSource());
response.setAttr("partner", "value", lead.getPartner());
response.setAttr("user", "value", lead.getUser());
response.setAttr("team", "value", lead.getTeam());
response.setAttr("webSite", "value", lead.getWebSite());
response.setAttr("source", "value", lead.getSource());
response.setAttr("department", "value", lead.getDepartment());
response.setAttr("isCustomer", "value", true);
response.setAttr("partnerTypeSelect", "value", "1");
response.setAttr("language", "value", appBase.getDefaultPartnerLanguage());
Company company = null;
CompanyRepository companyRepo = Beans.get(CompanyRepository.class);
if (lead.getUser() != null && lead.getUser().getActiveCompany() != null) {
company = lead.getUser().getActiveCompany();
} else if (companyRepo.all().count() == 1) {
company = companyRepo.all().fetchOne();
}
if (company != null) {
response.setAttr("company", "value", company);
response.setAttr("currency", "value", company.getCurrency());
}
}
use of com.axelor.apps.base.db.Company 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.apps.base.db.Company 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