Program: 58693
Project: 58693
Buggy source:
@Transactional public void insertKMExpenses(ActionRequest request,ActionResponse response){
  User user=AuthUtils.getUser();
  if (user != null) {
    Expense expense=Beans.get(ExpenseRepository.class).all().filter("String_Node_Str",user.getId()).order("String_Node_Str").fetchOne();
    if (expense == null) {
      expense=new Expense();
      expense.setUser(user);
      expense.setCompany(user.getActiveCompany());
      expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    }
    ExpenseLine expenseLine=new ExpenseLine();
    expenseLine.setDistance(new BigDecimal(request.getData().get("String_Node_Str").toString()));
    expenseLine.setFromCity(request.getData().get("String_Node_Str").toString());
    expenseLine.setToCity(request.getData().get("String_Node_Str").toString());
    expenseLine.setKilometricTypeSelect(new Integer(request.getData().get("String_Node_Str").toString()));
    expenseLine.setComments(request.getData().get("String_Node_Str").toString());
    expenseLine.setExpenseDate(new LocalDate(request.getData().get("String_Node_Str").toString()));
    if (user.getEmployee() != null && user.getEmployee().getKilometricAllowParam() != null) {
      expenseLine.setKilometricAllowParam(user.getEmployee().getKilometricAllowParam());
      KilometricAllowanceRate kilometricAllowanceRate=Beans.get(KilometricAllowanceRateRepository.class).findByVehicleKillometricAllowanceParam(user.getEmployee().getKilometricAllowParam());
      if (kilometricAllowanceRate != null) {
        BigDecimal rate=kilometricAllowanceRate.getRate();
        if (rate != null) {
          expenseLine.setTotalAmount(rate.multiply(expenseLine.getDistance()));
        }
      }
    }
    expense.addExpenseLineListItem(expenseLine);
    Beans.get(ExpenseRepository.class).save(expense);
  }
}

Fixed version (ground truth):
@Transactional public void insertKMExpenses(ActionRequest request,ActionResponse response) throws AxelorException {
  User user=AuthUtils.getUser();
  if (user != null) {
    Expense expense=Beans.get(ExpenseRepository.class).all().filter("String_Node_Str",user.getId()).order("String_Node_Str").fetchOne();
    if (expense == null) {
      expense=new Expense();
      expense.setUser(user);
      expense.setCompany(user.getActiveCompany());
      expense.setStatusSelect(TimesheetRepository.STATUS_DRAFT);
    }
    ExpenseLine expenseLine=new ExpenseLine();
    expenseLine.setDistance(new BigDecimal(request.getData().get("String_Node_Str").toString()));
    expenseLine.setFromCity(request.getData().get("String_Node_Str").toString());
    expenseLine.setToCity(request.getData().get("String_Node_Str").toString());
    expenseLine.setKilometricTypeSelect(new Integer(request.getData().get("String_Node_Str").toString()));
    expenseLine.setComments(request.getData().get("String_Node_Str").toString());
    expenseLine.setExpenseDate(new LocalDate(request.getData().get("String_Node_Str").toString()));
    Employee employee=user.getEmployee();
    if (employee != null && employee.getKilometricAllowParam() != null) {
      expenseLine.setKilometricAllowParam(user.getEmployee().getKilometricAllowParam());
      expenseLine.setTotalAmount(Beans.get(KilometricService.class).computeKilometricExpense(expenseLine,employee));
      expenseLine.setUntaxedAmount(expenseLine.getTotalAmount());
    }
    expense.addExpenseLineListItem(expenseLine);
    Beans.get(ExpenseRepository.class).save(expense);
  }
}