Beispiel #1
0
 def query(self):
     query = DBSESSION().query(Task)
     query = query.with_polymorphic([Invoice, CancelInvoice])
     query = query.outerjoin(Invoice.payments)
     query = query.outerjoin(Task.customer)
     query = query.options(
         contains_eager(Invoice.payments).load_only(Payment.id,
                                                    Payment.date,
                                                    Payment.mode))
     query = query.options(
         contains_eager(Task.customer).load_only(Customer.name,
                                                 Customer.code,
                                                 Customer.id))
     query = query.filter(Task.status == 'valid')
     return query
Beispiel #2
0
 def get_types(cls, active=True, keys=()):
     query = DBSESSION().query(cls)
     if keys:
         query = query.options(load_only(*keys))
     if active:
         query = query.filter_by(active=True)
     return query
Beispiel #3
0
 def find_by_login(cls, login, active=True):
     query = DBSESSION().query(cls)
     query = query.options(load_only('pwd_hash'))
     query = query.filter_by(login=login)
     if active:
         query = query.filter_by(active=True)
     return query.first()
Beispiel #4
0
 def find_by_login(cls, login, active=True):
     query = DBSESSION().query(cls)
     query = query.options(load_only('pwd_hash'))
     query = query.filter_by(login=login)
     if active:
         query = query.filter_by(active=True)
     return query.first()
 def get_types(cls, active=True, keys=()):
     query = DBSESSION().query(cls)
     if keys:
         query = query.options(load_only(*keys))
     if active:
         query = query.filter_by(active=True)
     return query
Beispiel #6
0
    def query(self):
        query = DBSESSION().query(Task)
        query = query.with_polymorphic([Invoice, CancelInvoice])
        query = query.outerjoin(Invoice.payments)
        query = query.outerjoin(Task.customer)
        query = query.outerjoin(Task.company)
        query = query.options(
            contains_eager(Invoice.payments).load_only(Payment.id,
                                                       Payment.date,
                                                       Payment.mode))
        query = query.options(
            contains_eager(Task.customer).load_only(
                Customer.name,
                Customer.code,
                Customer.id,
                Customer.firstname,
                Customer.lastname,
                Customer.civilite,
                Customer.type_,
            ))
        query = query.options(
            contains_eager(Task.company).load_only(
                Company.name,
                Company.id,
            ))
        query = query.options(
            load_only(
                "_acl",
                "name",
                "date",
                "id",
                "ht",
                "tva",
                "ttc",
                "company_id",
                "customer_id",
                "official_number",
                "internal_number",
                "prefix",
                "status",
                Invoice.paid_status,
            ))

        query = query.filter(Task.status == 'valid')
        return query
Beispiel #7
0
 def query(self):
     query = DBSESSION().query(Task)
     query = query.with_polymorphic([Invoice, CancelInvoice])
     query = query.outerjoin(Invoice.payments)
     query = query.outerjoin(Task.customer)
     query = query.outerjoin(Task.company)
     query = query.options(
         contains_eager(Invoice.payments).load_only(
             Payment.id, Payment.date, Payment.mode
         )
     )
     query = query.options(
         contains_eager(Task.customer).load_only(
             Customer.name, Customer.code, Customer.id,
             Customer.firstname, Customer.lastname, Customer.civilite,
             Customer.type_,
         )
     )
     query = query.options(
         contains_eager(Task.company).load_only(
             Company.name,
             Company.id,
         )
     )
     query = query.options(
         load_only(
             "_acl",
             "name",
             "date",
             "id",
             "ht",
             "tva",
             "ttc",
             "company_id",
             "customer_id",
             "official_number",
             "internal_number",
             "status",
             Invoice.paid_status,
         )
     )
     return query
Beispiel #8
0
 def get_categories(cls, active=True, keys=()):
     """
     :param bool active: Only load active categories
     :param tuple keys: The keys to load (list of str)
     :returns: IncomeStatementMeasureTypeCategory ordered by order key
     :rtype: list
     """
     query = DBSESSION().query(cls)
     if keys:
         query = query.options(load_only(*keys))
     query = query.filter_by(active=active).order_by(cls.order)
     return query.all()
 def get_categories(cls, active=True, keys=()):
     """
     :param bool active: Only load active categories
     :param tuple keys: The keys to load (list of str)
     :returns: IncomeStatementMeasureTypeCategory ordered by order key
     :rtype: list
     """
     query = DBSESSION().query(cls)
     if keys:
         query = query.options(load_only(*keys))
     query = query.filter_by(active=active).order_by(cls.order)
     return query.all()
Beispiel #10
0
    def get_by_category(cls, category_id, key=None):
        """
        Collect IncomeStatementMeasureType associated to the given category

        :param int category_id: The id to check for
        :param str key: The key to load (if we want to restrict the query
        :rtype: list
        """
        query = DBSESSION().query(cls)
        if key is not None:
            query = query.options(load_only(key))
        query = query.filter_by(category_id=category_id)
        return query.all()
    def get_by_category(cls, category_id, key=None):
        """
        Collect IncomeStatementMeasureType associated to the given category

        :param int category_id: The id to check for
        :param str key: The key to load (if we want to restrict the query
        :rtype: list
        """
        query = DBSESSION().query(cls)
        if key is not None:
            query = query.options(load_only(key))
        query = query.filter_by(category_id=category_id)
        return query.all()
Beispiel #12
0
 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)
Beispiel #13
0
 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)