use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ConfiguratorController method generateProduct.
/**
* Called from configurator form view, call {@link
* ConfiguratorService#generateProduct(Configurator, JsonContext, JsonContext)}
*
* @param request
* @param response
*/
public void generateProduct(ActionRequest request, ActionResponse response) {
Configurator configurator = request.getContext().asType(Configurator.class);
JsonContext jsonAttributes = (JsonContext) request.getContext().get("$attributes");
JsonContext jsonIndicators = (JsonContext) request.getContext().get("$indicators");
configurator = Beans.get(ConfiguratorRepository.class).find(configurator.getId());
try {
Beans.get(ConfiguratorService.class).generate(configurator, jsonAttributes, jsonIndicators);
response.setReload(true);
if (configurator.getProduct() != null) {
response.setView(ActionView.define(I18n.get("Product generated")).model(Product.class.getName()).add("form", "product-form").add("grid", "product-grid").param("search-filters", "products-filters").context("_showRecord", configurator.getProduct().getId()).map());
}
} catch (Exception e) {
TraceBackService.trace(e);
response.setError(e.getMessage());
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ProductBaseRepository method save.
@Override
public Product save(Product product) {
try {
if (appBaseService.getAppBase().getGenerateProductSequence() && Strings.isNullOrEmpty(product.getCode())) {
product.setCode(Beans.get(ProductService.class).getSequence(product));
}
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
product.setFullName(String.format(FULL_NAME_FORMAT, product.getCode(), product.getName()));
if (product.getId() != null) {
Product oldProduct = Beans.get(ProductRepository.class).find(product.getId());
translationService.updateFormatedValueTranslations(oldProduct.getFullName(), FULL_NAME_FORMAT, product.getCode(), product.getName());
} else {
translationService.createFormatedValueTranslations(FULL_NAME_FORMAT, product.getCode(), product.getName());
}
product = super.save(product);
if (product.getBarCode() == null && appBaseService.getAppBase().getActivateBarCodeGeneration()) {
try {
boolean addPadding = false;
InputStream inStream;
if (!appBaseService.getAppBase().getEditProductBarcodeType()) {
inStream = barcodeGeneratorService.createBarCode(product.getSerialNumber(), appBaseService.getAppBase().getBarcodeTypeConfig(), addPadding);
} else {
inStream = barcodeGeneratorService.createBarCode(product.getSerialNumber(), product.getBarcodeTypeConfig(), addPadding);
}
if (inStream != null) {
MetaFile barcodeFile = metaFiles.upload(inStream, String.format("ProductBarCode%d.png", product.getId()));
product.setBarCode(barcodeFile);
}
} catch (IOException e) {
e.printStackTrace();
} catch (AxelorException e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new ValidationException(e);
}
}
return super.save(product);
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ExpenseController method fillKilometricExpenseProduct.
public void fillKilometricExpenseProduct(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().getParent().asType(Expense.class);
Product expenseProduct = Beans.get(ExpenseService.class).getKilometricExpenseProduct(expense);
logger.debug("Get Kilometric expense product : {}", expenseProduct);
response.setValue("expenseProduct", expenseProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
int count = 0;
DateFormat ddmmFormat = new SimpleDateFormat("dd/MM");
HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<>();
// Check if a consolidation by product and user must be done
boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
for (TimesheetLine timesheetLine : timesheetLineList) {
Object[] tabInformations = new Object[5];
tabInformations[0] = timesheetLine.getProduct();
tabInformations[1] = timesheetLine.getUser();
// Start date
tabInformations[2] = timesheetLine.getDate();
// End date, useful only for consolidation
tabInformations[3] = timesheetLine.getDate();
tabInformations[4] = timesheetLine.getHoursDuration();
String key = null;
if (consolidate) {
key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId();
if (timeSheetInformationsMap.containsKey(key)) {
tabInformations = timeSheetInformationsMap.get(key);
// Update date
if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
// If date is lower than start date then replace start date by this one
tabInformations[2] = timesheetLine.getDate();
} else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
// If date is upper than end date then replace end date by this one
tabInformations[3] = timesheetLine.getDate();
}
tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getHoursDuration());
} else {
timeSheetInformationsMap.put(key, tabInformations);
}
} else {
key = String.valueOf(timesheetLine.getId());
timeSheetInformationsMap.put(key, tabInformations);
}
timesheetLine.setInvoiced(true);
}
for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
String strDate = null;
Product product = (Product) timesheetInformations[0];
User user = (User) timesheetInformations[1];
LocalDate startDate = (LocalDate) timesheetInformations[2];
LocalDate endDate = (LocalDate) timesheetInformations[3];
BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (consolidate) {
strDate = ddmmFormat.format(startDate) + " - " + ddmmFormat.format(endDate);
} else {
strDate = ddmmFormat.format(startDate);
}
invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
count++;
}
return invoiceLineList;
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createDefaultLines.
@Override
public List<Map<String, Object>> createDefaultLines(Timesheet timesheet) {
List<Map<String, Object>> lines = new ArrayList<>();
User user = timesheet.getUser();
if (user == null || timesheet.getFromDate() == null) {
return lines;
}
user = userRepo.find(user.getId());
Product product = userHrService.getTimesheetProduct(user);
if (product == null) {
return lines;
}
List<Project> projects = projectRepo.all().filter("self.membersUserSet.id = ?1 and " + "self.imputable = true " + "and self.statusSelect != 3", user.getId()).fetch();
for (Project project : projects) {
TimesheetLine line = timesheetLineService.createTimesheetLine(project, product, user, timesheet.getFromDate(), timesheet, new BigDecimal(0), null);
lines.add(Mapper.toMap(line));
}
return lines;
}
Aggregations