def query(self, query_params_dict): """ Base Query for expenses :param query_params_dict: params passed in the query for expense export """ query = ExpenseSheet.query() query = query.filter( ExpenseSheet.status.in_(ExpenseSheet.valid_states) ) if query_params_dict.get("sheet_id", 0) != 0: sheet_id = query_params_dict['sheet_id'] query = query.filter(ExpenseSheet.id == sheet_id) else: if "year" in query_params_dict: year = query_params_dict['year'] query = query.filter(ExpenseSheet.year == year) month = query_params_dict['month'] query = query.filter(ExpenseSheet.month == month) if query_params_dict.get('user_id', 0) != 0: user_id = query_params_dict['user_id'] query = query.filter(ExpenseSheet.user_id == user_id) if 'exported' not in query_params_dict or \ not query_params_dict.get('exported'): query = query.filter(ExpenseSheet.exported == False) return query
def query(self, query_params_dict): """ Base Query for expenses :param query_params_dict: params passed in the query for expense export """ query = ExpenseSheet.query() query = query.filter(ExpenseSheet.status.in_( ExpenseSheet.valid_states)) if query_params_dict.get("sheet_id", 0) != 0: sheet_id = query_params_dict['sheet_id'] query = query.filter(ExpenseSheet.id == sheet_id) else: if "year" in query_params_dict: year = query_params_dict['year'] query = query.filter(ExpenseSheet.year == year) month = query_params_dict['month'] query = query.filter(ExpenseSheet.month == month) if query_params_dict.get('user_id', 0) != 0: user_id = query_params_dict['user_id'] query = query.filter(ExpenseSheet.user_id == user_id) if 'exported' not in query_params_dict or \ not query_params_dict.get('exported'): query = query.filter(ExpenseSheet.exported == False) return query
def _get_expense_sheet(year, month, cid, uid): """ Return the expense sheet for the given 4-uple """ return ExpenseSheet.query()\ .filter(ExpenseSheet.year == year)\ .filter(ExpenseSheet.month == month)\ .filter(ExpenseSheet.company_id == cid)\ .filter(ExpenseSheet.user_id == uid).first()
def _get_expense_sheet(year, month, cid, uid): """ Return the expense sheet for the given 4-uple """ return ( ExpenseSheet.query() .filter(ExpenseSheet.year == year) .filter(ExpenseSheet.month == month) .filter(ExpenseSheet.company_id == cid) .filter(ExpenseSheet.user_id == uid) .first() )
def manage(request): """ The manage view """ estimations = Task.get_waiting_estimations().all() invoices = Task.get_waiting_invoices().all() for item in estimations: item.url = request.route_path(item.type_, id=item.id) for item in invoices: item.url = request.route_path(item.type_, id=item.id) expenses = ExpenseSheet.query()\ .filter(ExpenseSheet.status == 'wait')\ .order_by(ExpenseSheet.month)\ .order_by(ExpenseSheet.status_date).all() for expense in expenses: expense.url = request.route_path("expensesheet", id=expense.id) user_id = request.user.id query = Activity.query() query = query.join(Activity.conseillers) query = query.filter( Activity.conseillers.any(User.id == user_id) ) query = query.filter(Activity.status == 'planned') query = query.order_by(Activity.datetime).limit(10) activities = query.all() for activity in activities: activity.url = request.route_path("activity", id=activity.id) return dict( title=u"Documents en attente de validation", invoices=invoices, estimations=estimations, expenses=expenses, activities=activities, )
def get_new_expense_sheet(year, month, cid, uid): """ Return a new expense sheet for the given 4-uple """ expense = ExpenseSheet() expense.name = get_expense_sheet_name(month, year) expense.year = year expense.month = month expense.company_id = cid expense.user_id = uid query = ExpenseTelType.query() query = query.filter(ExpenseTelType.active == True) teltypes = query.filter(ExpenseTelType.initialize == True) for type_ in teltypes: line = ExpenseLine(type_id=type_.id, ht=0, tva=0, description=type_.label) expense.lines.append(line) return expense
def query(self): return ExpenseSheet.query().outerjoin(ExpenseSheet.user)