Search in sources :

Example 36 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProductionProjectedStockController method showConsumeQuantityOfProduct.

public void showConsumeQuantityOfProduct(ActionRequest request, ActionResponse response) {
    Map<String, Long> mapId = Beans.get(ProjectedStockService.class).getProductIdCompanyIdStockLocationIdFromContext(request.getContext());
    if (mapId == null || mapId.get("productId") == 0L) {
        return;
    }
    Long productId = mapId.get("productId");
    Long companyId = mapId.get("companyId");
    Long stockLocationId = mapId.get("stockLocationId");
    String domain = Beans.get(ManufOrderService.class).getConsumeAndMissingQtyForAProduct(productId, companyId, stockLocationId);
    Product product = Beans.get(ProductRepository.class).find(mapId.get("productId"));
    String title = I18n.get(VIEW_CONSUME_QTY_TITLE);
    title = String.format(title, product.getName());
    response.setView(ActionView.define(title).model(StockMoveLine.class.getName()).add("grid", "stock-move-line-consumed-manuf-order-grid").add("form", "stock-move-line-form").domain(domain).param("popup", "true").param("popup-save", "false").map());
}
Also used : ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product)

Example 37 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class InvoiceLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    Product product = invoiceLine.getProduct();
    Map<String, Object> productInformation = new HashMap<>();
    if (invoice != null && product != null) {
        try {
            productInformation = Beans.get(InvoiceLineService.class).fillProductInformation(invoice, invoiceLine);
            String errorMsg = (String) productInformation.get("error");
            if (!Strings.isNullOrEmpty(errorMsg)) {
                response.setFlash(errorMsg);
            }
        } catch (Exception e) {
            TraceBackService.trace(response, e);
        }
    } else {
        productInformation = Beans.get(InvoiceLineService.class).resetProductInformation(invoice);
    }
    response.setValues(productInformation);
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 38 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ExpenseServiceImpl method createAndSetMove.

protected Move createAndSetMove(Expense expense) throws AxelorException {
    LocalDate moveDate = expense.getMoveDate();
    if (moveDate == null) {
        moveDate = appAccountService.getTodayDate(expense.getCompany());
        expense.setMoveDate(moveDate);
    }
    Company company = expense.getCompany();
    Partner partner = expense.getUser().getPartner();
    Account account = null;
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    if (partner == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
    }
    Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
    List<MoveLine> moveLines = new ArrayList<>();
    Set<AnalyticAccount> analyticAccounts = new HashSet<>();
    BigDecimal exTaxTotal = null;
    int moveLineId = 1;
    int expenseLineId = 1;
    Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
    moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        analyticAccounts.clear();
        Product product = expenseLine.getExpenseProduct();
        account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
        if (account == null) {
            throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
        }
        exTaxTotal = expenseLine.getUntaxedAmount();
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
        for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
            AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
            analyticDistributionLine.setExpenseLine(null);
            moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
        }
        moveLines.add(moveLine);
        expenseLineId++;
    }
    moveLineService.consolidateMoveLines(moveLines);
    account = accountConfigService.getExpenseTaxAccount(accountConfig);
    BigDecimal taxTotal = BigDecimal.ZERO;
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        exTaxTotal = expenseLine.getTotalTax();
        taxTotal = taxTotal.add(exTaxTotal);
    }
    if (taxTotal.signum() != 0) {
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
        moveLines.add(moveLine);
    }
    move.getMoveLineList().addAll(moveLines);
    moveService.getMoveValidateService().validate(move);
    expense.setMove(move);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) Partner(com.axelor.apps.base.db.Partner) HashSet(java.util.HashSet) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 39 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class HumanResourceMobileController method getExpensesTypes.

/*
   * This method is used in mobile application.
   * It was in ExpenseServiceImpl
   * @param request
   * @param response
   *
   * POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:getExpensesTypes
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:getExpensesTypes
   * fields: no field
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:getExpensesTypes"
   * } }
   */
@Transactional
public void getExpensesTypes(ActionRequest request, ActionResponse response) {
    List<Map<String, String>> dataList = new ArrayList<>();
    try {
        List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.expense = true AND coalesce(self.unavailableToUsers, false) = false AND coalesce(self.personalExpense, false) = false AND self.dtype = 'Product'").fetch();
        for (Product product : productList) {
            Map<String, String> map = new HashMap<>();
            map.put("name", product.getName());
            map.put("id", product.getId().toString());
            dataList.add(map);
        }
        response.setData(dataList);
        response.setTotal(dataList.size());
    } catch (Exception e) {
        response.setStatus(-1);
        response.setError(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) HashMap(java.util.HashMap) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 40 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class HumanResourceMobileController method insertOrUpdateTSLine.

/*
   * This method is used in mobile application.
   * It was in TimesheetServiceImpl
   * @param request
   * @param response
   *
   * POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
   * fields: (id,) project, activity, date, duration, comments
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine",
   *        "id": 1,
   * 		"project": 1,
   * 		"activity": 2,
   * 		"date": "2018-02-22",
   * 		"duration": 10,
   * 		"comments": "no"
   * } }
   */
@Transactional
public void insertOrUpdateTSLine(ActionRequest request, ActionResponse response) {
    // insert TimesheetLine
    try {
        Map<String, Object> requestData = request.getData();
        User user = AuthUtils.getUser();
        Project project = Beans.get(ProjectRepository.class).find(new Long(request.getData().get("project").toString()));
        Product product = Beans.get(ProductRepository.class).find(new Long(request.getData().get("activity").toString()));
        LocalDate date = LocalDate.parse(request.getData().get("date").toString(), DateTimeFormatter.ISO_DATE);
        TimesheetRepository timesheetRepository = Beans.get(TimesheetRepository.class);
        TimesheetService timesheetService = Beans.get(TimesheetService.class);
        TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
        if (user != null) {
            Timesheet timesheet = timesheetRepository.all().filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
            if (timesheet == null) {
                timesheet = timesheetService.createTimesheet(user, date, date);
            }
            BigDecimal hours = new BigDecimal(request.getData().get("duration").toString());
            TimesheetLine line;
            Object idO = requestData.get("id");
            if (idO != null) {
                line = timesheetLineService.updateTimesheetLine(Beans.get(TimesheetLineRepository.class).find(Long.valueOf(idO.toString())), project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
            } else {
                line = timesheetLineService.createTimesheetLine(project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
            }
            // convert hours to what is defined in timeLoggingPreferenceSelect
            BigDecimal duration = timesheetLineService.computeHoursDuration(timesheet, hours, false);
            line.setDuration(duration);
            timesheet.addTimesheetLineListItem(line);
            timesheetRepository.save(timesheet);
            response.setTotal(1);
            HashMap<String, Object> data = new HashMap<>();
            data.put("id", line.getId());
            response.setData(data);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
}
Also used : User(com.axelor.auth.db.User) ProjectRepository(com.axelor.apps.project.db.repo.ProjectRepository) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) HashMap(java.util.HashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) Transactional(com.google.inject.persist.Transactional)

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