Search in sources :

Example 16 with Product

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());
    }
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Configurator(com.axelor.apps.sale.db.Configurator) Product(com.axelor.apps.base.db.Product) ConfiguratorService(com.axelor.apps.sale.service.configurator.ConfiguratorService)

Example 17 with Product

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) ValidationException(javax.validation.ValidationException) InputStream(java.io.InputStream) PersistenceException(javax.persistence.PersistenceException) Product(com.axelor.apps.base.db.Product) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) IOException(java.io.IOException) AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException) ValidationException(javax.validation.ValidationException)

Example 18 with 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);
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) Product(com.axelor.apps.base.db.Product) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 19 with Product

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;
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) PriceList(com.axelor.apps.base.db.PriceList)

Example 20 with Product

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;
}
Also used : Project(com.axelor.apps.project.db.Project) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16