Example #1
0
    def get(self, customer_id=None):
        if customer_id:
            customer = Customer.query.options(
                joinedload('customer_projects'),
                joinedload('customer_projects.installations'),
                joinedload(
                    'customer_projects.installations.panels.panel_model'),
                joinedload(
                    'customer_projects.installations.inverters.inverter_model'
                ),
                joinedload(
                    'customer_projects.installations.installation_documents'),
                joinedload('customer_projects.installations.status'),
                joinedload('customer_projects.installations.financing'),
                joinedload('customer_projects.installations.financing.status'),
                joinedload(
                    'customer_projects.installations.financing.financial_entity'
                )).filter_by(id=customer_id)

            return Result.model(customer.first())

        page = request.args.get('page', 1)
        total_pages = 1
        q = request.args.get('query')

        if q:
            customers = Customer.query.filter(
                (Customer.first_name.like('%' + q + '%'))
                | (Customer.last_name.like('%' + q + '%'))
                | (Customer.primary_email.like('%' + q + '%'))
                | (Customer.primary_phone.like('%' + q + '%'))(
                    Customer.identification_number.like('%' + q + '%'))).all()
        else:
            paginator = Paginator(Customer.query, int(page),
                                  request.args.get('orderBy', 'last_name'),
                                  request.args.get('orderDir', 'desc'))
            total_pages = paginator.total_pages
            customers = paginator.get_items()

        return Result.paginate(customers, page, total_pages)
Example #2
0
 def get(self):
     return Result.model(InverterModel.query.all())
Example #3
0
 def get(self):
     return Result.model(PanelModel.query.all())
Example #4
0
 def get(self):
     return Result.model(Tension.query.all())
Example #5
0
 def get(self):
     return Result.model(Phase.query.all())
Example #6
0
 def get(self):
     return Result.model(TrCapacity.query.all())
Example #7
0
 def get(self):
     return Result.model(Transformer.query.all())
Example #8
0
 def get(self):
     return Result.model(Rate.query.all())
Example #9
0
 def get(self):
     return Result.model(Distributor.query.all())
Example #10
0
 def get(self):
     return Result.model(ProjectType.query.all())
Example #11
0
 def get(self):
     return Result.model(SourceProject.query.all())
Example #12
0
 def get(self):
     return Result.model(
         Country.query.options(joinedload('provinces')).all())
Example #13
0
 def get(self):
     return Result.model(FinancialStatus.query.all())
Example #14
0
 def get(self):
     return Result.model(FinancialEntity.query.all())
Example #15
0
 def get(self):
     return Result.model(SaleType.query.all())
Example #16
0
 def get(self):
     return Result.model(CompanyProfile.query.first())