Ejemplo n.º 1
0
    def read(self, request, code="", warehouse="", destination="", consignee="", format=""):
        """Return orders in CSV"""

        orders = self.model.objects.all()
        orders = orders.filter(**filter_for_orders())
     
        if not request.user.has_perm("ets.order_api_full_access"):
            orders = orders.filter(warehouse__persons__pk=request.user.pk)

        if request.GET.has_key('sSearch'):
            orders = get_datatables_filtering(request, orders)
        
        filter_arg = {}
        if warehouse: 
            filter_arg['warehouse__pk'] = warehouse
        if destination:
            filter_arg['consignee__warehouses__pk'] = destination
        if consignee:
            filter_arg['consignee__pk'] = consignee
        if code:
            filter_arg['code'] = code
        if filter_arg:
            orders = orders.filter(**filter_arg)
        
        return orders
Ejemplo n.º 2
0
    def read(self, request, slug="", warehouse="", destination="", filtering=None, **kwargs):
        """Return waybills in CSV"""
        waybills = self.model.objects.all()

        if filtering:
            officer_required = ets.models.Compas.objects.filter(officers=request.user).exists()

            filter_choice = {
                'dispatches': lambda user: self.model.dispatches(user),
                'receptions': lambda user: self.model.receptions(user),
                'user_related': lambda user: waybill_user_related_filter(waybills, user),
                'compas_receipt': lambda user: waybill_officer_related_filter(waybills.filter(receipt_sent_compas__isnull=False), user),
                'compas_dispatch': lambda user: waybill_officer_related_filter(waybills.filter(sent_compas__isnull=False), user),
                'validate_receipt': lambda user: officer_required and waybills.filter(**get_receipt_compas_filters(user)).filter(receipt_validated=False),
                'validate_dispatch': lambda user: officer_required and waybills.filter(**get_dispatch_compas_filters(user)).filter(validated=False),
                'dispatch_validated': lambda user: officer_required and waybills.filter(**get_dispatch_compas_filters(user)).filter(validated=True),
                'receipt_validated': lambda user: officer_required and waybills.filter(**get_receipt_compas_filters(user)).filter(receipt_validated=True),
            }
            waybills = filter_choice[filtering](request.user)

        elif not request.user.has_perm("ets.waybill_api_full_access"):
            waybills = waybills.filter(order__warehouse__persons__pk=request.user.pk)

        if request.GET.has_key('sSearch'):
            waybills = get_datatables_filtering(request, waybills)

        return waybills
Ejemplo n.º 3
0
    def read(self, request, slug="", warehouse="", destination="", filtering=None, format=""):
        """Return waybills in CSV"""
        waybills = self.model.objects.all()

        if filtering:
            officer_required = ets.models.Compas.objects.filter(officers=request.user).exists()

            # 1 variant
            filter_choice = {
                'dispatches': lambda user: self.model.dispatches(user),
                'receptions': lambda user: self.model.receptions(user),
                'user_related': lambda user: waybill_user_related_filter(waybills, user),
                'compas_receipt': lambda user: waybill_officer_related_filter(waybills.filter(receipt_sent_compas__isnull=False), user),
                'compas_dispatch': lambda user: waybill_officer_related_filter(waybills.filter(sent_compas__isnull=False), user),
                'validate_receipt': lambda user: officer_required and waybills.filter(**get_receipt_compas_filters(user)).filter(receipt_validated=False),
                'validate_dispatch': lambda user: officer_required and waybills.filter(**get_dispatch_compas_filters(user)).filter(validated=False),
                'dispatch_validated': lambda user: officer_required and waybills.filter(**get_dispatch_compas_filters(user)).filter(validated=True),
                'receipt_validated': lambda user: officer_required and waybills.filter(**get_receipt_compas_filters(user)).filter(receipt_validated=True),
            }
            waybills = filter_choice[filtering](request.user)

            # 2 variant
            # if filtering == 'dispatches':
            #     waybills = self.model.dispatches(request.user)
            # elif filtering == 'receptions':
            #     waybills = self.model.receptions(request.user)
            # elif filtering == 'user_related':
            #     waybills = waybill_user_related_filter(waybills, request.user)
            # elif filtering == 'compas_receipt':
            #     waybills = waybill_officer_related_filter(waybills.filter(receipt_sent_compas__isnull=False), request.user)
            # elif filtering == 'compas_dispatch':
            #     waybills = waybill_officer_related_filter(waybills.filter(sent_compas__isnull=False), request.user)
            # elif filtering == 'validate_receipt' and officer_required:
            #     waybills = waybills.filter(**get_receipt_compas_filters(request.user)).filter(receipt_validated=False)
            # elif filtering == 'validate_dispatch' and officer_required:
            #     waybills = waybills.filter(**get_dispatch_compas_filters(request.user)).filter(validated=False)
            # elif filtering == 'dispatch_validated' and officer_required:
            #     waybills = waybills.filter(**get_dispatch_compas_filters(request.user)).filter(validated=True)
            # elif filtering == 'receipt_validated' and officer_required:
            #     waybills = waybills.filter(**get_receipt_compas_filters(request.user)).filter(receipt_validated=True)
                
        elif not request.user.has_perm("ets.waybill_api_full_access"):
            waybills = waybills.filter(order__warehouse__persons__pk=request.user.pk)

        if request.GET.has_key('sSearch'):
            waybills = get_datatables_filtering(request, waybills)

        filter_arg = {}
        if warehouse: 
            filter_arg['order__warehouse__pk'] = warehouse
        if destination:
            filter_arg['destination__pk'] = destination
        if slug:
            filter_arg['slug'] = slug
        if filter_arg:
            waybills = waybills.filter(**filter_arg)

        return waybills
Ejemplo n.º 4
0
    def read(self, request, **kwargs):
        """country, location. warehouse information"""

        warehouses = self.model.objects.all()

        if request.GET.has_key('sSearch'):
            warehouses = get_datatables_filtering(request, self.model.get_active_warehouses())
        elif not request.user.is_superuser:
            warehouses = warehouses.filter(Q(persons__pk=request.user.pk) | Q(compas__officers=request.user))

        return warehouses
Ejemplo n.º 5
0
    def read(self, request, code="", warehouse="", destination="", consignee="", **kwargs):
        """Return orders"""

        orders = self.model.objects.all()
        orders = orders.filter(**filter_for_orders())
     
        if not request.user.has_perm("ets.order_api_full_access"):
            orders = orders.filter(warehouse__persons__pk=request.user.pk)

        if request.GET.has_key('sSearch'):
            orders = get_datatables_filtering(request, orders)
        
        return orders
Ejemplo n.º 6
0
    def read(self, request, warehouse="", **kwargs):
        """Finds all sent waybills to provided destination"""

        stock_items = self.model.objects.all()

        if request.GET.has_key('sSearch'):
            stock_items = get_datatables_filtering(request, stock_items)
        elif not request.user.is_superuser and not request.user.has_perm("ets.loadingetail_api_full_access"):
            stock_items = stock_items.filter(Q(warehouse__persons__pk=request.user.pk) | Q(warehouse__compas__officers=request.user))

        if warehouse: 
            stock_items = stock_items.filter(warehouse__pk=warehouse)

        return stock_items
Ejemplo n.º 7
0
    def read(self, request, warehouse="", format=""):
        """Finds all sent waybills to provided destination"""

        stock_items = self.model.objects.all()

        if request.GET.has_key('sSearch'):
            stock_items = get_datatables_filtering(request, stock_items)
        elif not request.user.has_perm("ets.stockitem_api_full_access"):
            stock_items = stock_items.filter(warehouse__persons__pk=request.user.pk)

        if warehouse: 
            stock_items = stock_items.filter(warehouse__pk=warehouse)

        return stock_items