Пример #1
0
 def resolve_customers(self, info, **kwargs):
     page_count = kwargs.get('page_count')
     page_number = kwargs.get('page_number')
     resolved_value = Profile.objects.all().order_by('id')
     if page_count or page_number:
         customers = pagination_query(resolved_value, page_count,
                                      page_number)
         Query.pagination_result = customers
         return customers[0]
     paginated_response = pagination_query(
         resolved_value, PAGINATION_DEFAULT["page_count"],
         PAGINATION_DEFAULT["page_number"])
     Query.pagination_result = paginated_response
     return paginated_response[0]
Пример #2
0
 def resolve_all_suppliers_note(self, info, **kwargs):
     page_count = kwargs.get('page_count')
     page_number = kwargs.get('page_number')
     suppliers_notes_set = SupplierNote.objects.all().order_by('id')
     if page_count or page_number:
         suppliers_notes = pagination_query(
             suppliers_notes_set, page_count, page_number)
         Query.pagination_result = suppliers_notes
         return suppliers_notes[0]
     paginated_response = pagination_query(suppliers_notes_set,
                                           PAGINATION_DEFAULT[
                                               "page_count"],
                                           PAGINATION_DEFAULT[
                                               "page_number"])
     Query.pagination_result = paginated_response
     return paginated_response[0]
Пример #3
0
    def resolve_all_sales_history(self, info, **kwargs):
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')

        resolved_value = Sale.objects.all()

        if page_count or page_number:
            sales = pagination_query(resolved_value, page_count, page_number)
            Query.pagination_result = sales
            return sales[0]
        if resolved_value:
            paginated_response = pagination_query(
                resolved_value, PAGINATION_DEFAULT["page_count"],
                PAGINATION_DEFAULT["page_number"])

            Query.pagination_result = paginated_response
            return paginated_response[0]
        return GraphQLError(SALES_ERROR_RESPONSES["no_sales_error"])
Пример #4
0
 def resolve_events(self, info, **kwargs):
     page_count = kwargs.get('page_count')
     page_number = kwargs.get('page_number')
     user = info.context.user
     outlet = check_user_has_an_active_outlet(user)
     events_set = Event.objects.filter(Q(user=user)
                                       | Q(outlet=outlet)).order_by('id')
     if page_count or page_number:
         events = pagination_query(events_set, page_count, page_number)
         Query.pagination_result = events
         return events[0]
     if events_set:
         paginated_response = pagination_query(
             events_set, PAGINATION_DEFAULT["page_count"],
             PAGINATION_DEFAULT["page_number"])
         Query.pagination_result = paginated_response
         return paginated_response[0]
     return GraphQLError(EVENTS_ERROR_RESPONSES["no_events_error"])
Пример #5
0
    def resolve_customer_credits(self, info, **kwargs):

        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        resolved_values = CustomerCredit.objects.all()
        if page_count or page_number:
            customer_credits = pagination_query(
                resolved_values, page_count, page_number
            )

            CustomerCreditQuery.pagination_result = customer_credits
            return customer_credits[0]

        paginated_response = pagination_query(
            resolved_values,
            PAGINATION_DEFAULT['page_count'],
            PAGINATION_DEFAULT['page_number'])
        CustomerCreditQuery.pagination_result = paginated_response
        return paginated_response[0]
Пример #6
0
    def resolve_orders(self, info, **kwargs):
        """
        gets all orders

        Returns:
            list: orders
        """
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        orders_set = Order.objects.all().order_by('id')
        if page_count or page_number:
            orders = pagination_query(orders_set, page_count, page_number)
            Query.pagination_result = orders
            return orders[0]
        paginated_response = pagination_query(
            orders_set, PAGINATION_DEFAULT["page_count"],
            PAGINATION_DEFAULT["page_number"])
        Query.pagination_result = paginated_response
        return paginated_response[0]
Пример #7
0
 def resolve_approved_suppliers(self, info, **kwargs):
     page_count = kwargs.get('page_count')
     page_number = kwargs.get('page_number')
     user = info.context.user
     approved_suppliers_set = Suppliers.objects.filter(
         is_approved=True, business=user.active_outlet.business
     ).order_by('id')
     if page_count or page_number:
         approved_suppliers = pagination_query(
             approved_suppliers_set, page_count, page_number)
         Query.pagination_result = approved_suppliers
         return approved_suppliers[0]
     paginated_response = pagination_query(approved_suppliers_set,
                                           PAGINATION_DEFAULT[
                                               "page_count"],
                                           PAGINATION_DEFAULT[
                                               "page_number"])
     Query.pagination_result = paginated_response
     return paginated_response[0]
Пример #8
0
    def resolve_closed_orders(self, info, **kwargs):
        """
        gets orders that have been closed

        Returns:
            list: closed orders
        """
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        closed_orders_set = Order.objects.filter(closed=True).order_by('id')
        if page_count or page_number:
            closed_orders = pagination_query(closed_orders_set, page_count,
                                             page_number)
            Query.pagination_result = closed_orders
            return closed_orders[0]
        paginated_response = pagination_query(
            closed_orders_set, PAGINATION_DEFAULT["page_count"],
            PAGINATION_DEFAULT["page_number"])
        Query.pagination_result = paginated_response
        return paginated_response[0]
Пример #9
0
    def resolve_open_orders(self, info, **kwargs):
        """
        gets orders that are open

        Returns:
            list: open orders
        """
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        open_orders_set = Order.objects.filter(closed=False).order_by('id')
        if page_count or page_number:
            open_orders = pagination_query(open_orders_set, page_count,
                                           page_number)
            Query.pagination_result = open_orders
            return open_orders[0]
        paginated_response = pagination_query(
            open_orders_set, PAGINATION_DEFAULT["page_count"],
            PAGINATION_DEFAULT["page_number"])
        Query.pagination_result = paginated_response
        return paginated_response[0]
    def resolve_consultations(self, info, **kwargs):
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        user = info.context.user
        outlet = get_model_object(Outlet, 'id', user.active_outlet.id)
        business_id = outlet.business_id

        all_consultations = ConsultationCatalogue.objects.filter(
            business=business_id).order_by("id")
        if page_count or page_number:
            consultations = pagination_query(
                all_consultations, page_count, page_number)
            Query.pagination_result = consultations
            return consultations[0]
        paginated_response = pagination_query(all_consultations,
                                              PAGINATION_DEFAULT["page_count"],
                                              PAGINATION_DEFAULT["page_number"]
                                              )
        Query.pagination_result = paginated_response
        return paginated_response[0]
Пример #11
0
    def resolve_outlet_sales_history(self, info, **kwargs):
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        search = kwargs.get('search')
        outlet_id = kwargs.get('outlet_id')

        sale = Sale()
        resolved_value = sale.sales_history(outlet_id=outlet_id, search=search)

        if page_count or page_number:
            sales = pagination_query(resolved_value, page_count, page_number)
            Query.pagination_result = sales
            return sales[0]
        if resolved_value:
            paginated_response = pagination_query(
                resolved_value, PAGINATION_DEFAULT["page_count"],
                PAGINATION_DEFAULT["page_number"])

            Query.pagination_result = paginated_response
            return paginated_response[0]
        return GraphQLError(SALES_ERROR_RESPONSES["no_sales_error"])
    def resolve_bookings(self, info, **kwargs):
        page_count = kwargs.get('page_count')
        page_number = kwargs.get('page_number')
        user_outlet = info.context.user.active_outlet.id
        all_customer_consultations = CustomerConsultation.objects.filter(
            outlet_id=user_outlet).order_by("id")

        if len(all_customer_consultations) > 0:
            if page_count or page_number:
                customer_consultations = pagination_query(
                    all_customer_consultations, page_count, page_number)
                Query.pagination_result = customer_consultations
                return customer_consultations[0]
            paginated_response =\
                pagination_query(all_customer_consultations,
                                 PAGINATION_DEFAULT["page_count"],
                                 PAGINATION_DEFAULT["page_number"]
                                 )
            Query.pagination_result = paginated_response
            return paginated_response[0]
        error = CONSULTATION_ERROR_RESPONSES["no_scheduled_consultations"]
        raise GraphQLError(error)