def query(cls, keys=None, active=True): """ Return a query """ if keys: query = DBSESSION().query(*keys) else: query = super(Company, cls).query() if active: query = query.filter(cls.active == "Y") return query.order_by(cls.name)
def taskyears(): """ return the distinct financial years available in the database """ query = DBSESSION().query(distinct(Invoice.financial_year)) query = query.order_by(Invoice.financial_year) years = [year[0] for year in query] current = datetime.date.today().year if current not in years: years.append(current) return years
def expenseyears(): """ return distinct expense years available in the database """ query = DBSESSION().query(distinct(ExpenseSheet.year)) query = query.order_by(ExpenseSheet.year) years = [year[0] for year in query] current = datetime.date.today().year if current not in years: years.append(current) return years
def query(cls, keys=None, active=True): """ Return a query """ if keys: query = DBSESSION().query(*keys) else: query = super(Company, cls).query() if active: query = query.filter(cls.active == True) return query.order_by(cls.name)
def get_expensesheet_years(company): """ List of years an expensesheet has been retrieved for """ query = DBSESSION().query(distinct( ExpenseSheet.year)).filter_by(company_id=company.id) years = [data[0] for data in query.order_by(desc(ExpenseSheet.year))] today = datetime.date.today() if today.year not in years: years.insert(0, today.year) return years
def get_tasks(cls, instance, offset=None, limit=None): from autonomie.models.task import Task query = DBSESSION().query(Task) query = query.filter(Task.company_id == instance.id) query = query.filter( Task.type_.in_(('invoice', 'estimation', 'cancelinvoice'))) query = query.order_by(desc(Task.status_date)) if offset is not None: query = query.offset(offset) if limit is not None: query = query.limit(limit) return query
def get_expensesheet_years(company): """ List of years an expensesheet has been retrieved for """ query = DBSESSION().query(distinct(ExpenseSheet.year)).filter_by( company_id=company.id ) years = [data[0] for data in query.order_by(desc(ExpenseSheet.year))] today = datetime.date.today() if today.year not in years: years.insert(0, today.year) return years
def get_tasks(cls, instance, offset=None, limit=None): from autonomie.models.task import Task query = DBSESSION().query(Task) query = query.filter(Task.company_id == instance.id) query = query.filter( Task.type_.in_(('invoice', 'estimation', 'cancelinvoice')) ) query = query.order_by(desc(Task.status_date)) if offset is not None: query = query.offset(offset) if limit is not None: query = query.limit(limit) return query
def get_customer_codes_and_names(cls, company): """ Return a query for code and names of customers related to company :param company: the company we're working on :returns: an orm query loading Customer instances with only the columns we want :rtype: A Sqlalchemy query object """ from autonomie.models.customer import Customer query = DBSESSION().query(Customer) query = query.options(load_only('code', 'name')) query = query.filter(Customer.code != None) query = query.filter(Customer.company_id == company.id) return query.order_by(Customer.code)
def get_users_options(roles=None): """ Return the list of active users from the database formatted as choices: [(user_id, user_label)...] :param role: roles of the users we want default: all values : ('contractor', 'manager', 'admin')) """ query = DBSESSION().query(User).options( load_only('id', 'firstname', 'lastname')) # Only User accounts with logins query = query.join(Login).filter(Login.active == True) query = query.order_by(User.lastname) if roles and not hasattr(roles, "__iter__"): roles = [roles] query = _filter_by_group(query, roles) return [(unicode(u.id), format_account(u)) for u in query]
def get_users_options(roles=None): """ Return the list of active users from the database formatted as choices: [(user_id, user_label)...] :param role: roles of the users we want default: all values : ('contractor', 'manager', 'admin')) """ query = DBSESSION().query(User).options( load_only('id', 'firstname', 'lastname') ) # Only User accounts with logins query = query.join(Login).filter(Login.active == True) query = query.order_by(User.lastname) if roles and not hasattr(roles, "__iter__"): roles = [roles] query = _filter_by_group(query, roles) return [(unicode(u.id), format_account(u)) for u in query]
def last(cls, grid_class, company_id): query = DBSESSION().query(grid_class).filter_by(company_id=company_id) query = query.order_by(desc(grid_class.date)) return query.first()