예제 #1
0
def get_queryset_sale_promotion_form_list(request):
    sale_promotion_form_obj = SalePromotion

    queryset = sale_promotion_form_obj.objects.filter(
        staff__in=get_staffs_viewable_queryset(request.user))

    title_id = request.query_params.get('title_id', None)
    terminal_id = request.query_params.get('terminal_id', None)
    shop_id = request.query_params.get('shop_id', None)
    staff_id = request.query_params.get('staff_id', None)
    team_id = request.query_params.get('team_id', None)
    status = request.query_params.get('status', None)

    if title_id is not None and title_id != '':
        queryset = queryset.filter(title_id=title_id)
    if terminal_id is not None and terminal_id != '':
        queryset = queryset.filter(terminal__id=terminal_id)
    if shop_id is not None and shop_id != '':
        queryset = queryset.filter(shop__id=shop_id)
    if staff_id is not None and staff_id != '':
        queryset = queryset.filter(staff_id=staff_id)
    if team_id is not None and team_id != '':
        staffs = Staff.objects.filter(team_id=team_id)
        queryset = queryset.filter(staff__in=staffs)
    if status is not None and status != '':
        queryset = queryset.filter(status=status)

    return queryset.order_by('-id')
예제 #2
0
def get_queryset_pos365_list(request):
    pos365_obj = Pos365

    queryset = pos365_obj.objects.filter(
        Q(staff__in=get_staffs_viewable_queryset(request.user))
        | Q(contract_team__in=get_teams_viewable_queryset(request.user)))

    code = request.query_params.get('code', None)
    staff_id = request.query_params.get('staff_id', None)
    contract_duration = request.query_params.get('contract_duration', None)
    province_id = request.query_params.get('province_id', None)
    from_date = request.query_params.get('from_date', None)
    to_date = request.query_params.get('to_date', None)

    if code is not None and code != '':
        code = format_string(code)
        queryset = queryset.filter(code__icontains=code)
    if staff_id is not None and staff_id != '':
        queryset = queryset.filter(staff_id=staff_id)
    if contract_duration is not None and contract_duration != '':
        contract_duration = int(contract_duration)
        queryset = queryset.filter(contract_duration=contract_duration)
    if province_id is not None and province_id != '':
        queryset = queryset.filter(customer_province=province_id)
    if from_date is not None and from_date != '':
        queryset = queryset.filter(
            contract_start_date__gte=dt_datetime.strptime(
                from_date, '%d/%m/%Y').strftime('%Y-%m-%d %H:%M:%S'))
    if to_date is not None and to_date != '':
        queryset = queryset.filter(contract_start_date__lte=(
            dt_datetime.strptime(to_date, '%d/%m/%Y').strftime('%Y-%m-%d') +
            ' 23:59:59'))
    return queryset
예제 #3
0
    def retrieve(self, request, pk):
        """
            API get detail Staff
        """

        if request.user.is_superuser is False:
            staffs = get_staffs_viewable_queryset(request.user)
            staff = Staff.objects.filter(pk=pk, pk__in=staffs).first()
        else:
            staff = Staff.objects.filter(pk=pk).first()

        if staff is None:
            return custom_response(Code.STAFF_NOT_FOUND)

        team = {
            "name":
            staff.team.name,
            "code":
            staff.team.code,
            "created_date":
            formats.date_format(staff.team.created_date,
                                "SHORT_DATETIME_FORMAT")
            if staff.team.created_date else '',
        } if staff.team is not None else None

        data = {
            'full_name':
            staff.full_name,
            'code':
            staff.staff_code,
            'email':
            staff.email,
            'mobile':
            staff.mobile,
            'status':
            staff.status,
            'team':
            team,
            'role':
            staff.get_role_name(),
            'created_date':
            formats.date_format(staff.created_date, "SHORT_DATETIME_FORMAT")
            if staff.created_date else '',
        }

        return successful_response(data)
예제 #4
0
    def get_queryset(self):

        queryset = Staff.objects.all()

        if self.request.user.is_superuser is False:
            staffs = get_staffs_viewable_queryset(self.request.user)
            queryset = queryset.filter(pk__in=staffs)

        staff_code = self.request.query_params.get('staff_code', None)
        team_id = self.request.query_params.get('team_id', None)
        role = self.request.query_params.get('role', None)
        status = self.request.query_params.get('status', None)
        from_date = self.request.query_params.get('from_date', None)
        to_date = self.request.query_params.get('to_date', None)

        if staff_code is not None and staff_code != '':
            staff_code = format_string(staff_code)
            queryset = queryset.filter(
                Q(staff_code__icontains=staff_code)
                | Q(full_name__icontains=staff_code)
                | Q(email__icontains=staff_code))
        if team_id is not None and team_id != '':
            if team_id == '0':
                queryset = queryset.filter(team__isnull=True)
            else:
                queryset = queryset.filter(team_id=team_id)
        if role is not None and role != '':
            if role.isdigit():
                if int(role) == 2:
                    queryset = queryset.filter(Q(role=int(role)) | Q(role=0))
                else:
                    queryset = queryset.filter(role=int(role))
        if status is not None and status != '':
            queryset = queryset.filter(status=(1 if status == '1' else -1))
        if from_date is not None and from_date != '':
            queryset = queryset.filter(created_date__gte=datetime.strptime(
                from_date, '%d/%m/%Y').strftime('%Y-%m-%d %H:%M:%S'))
        if to_date is not None and to_date != '':
            queryset = queryset.filter(created_date__lte=(
                datetime.strptime(to_date, '%d/%m/%Y').strftime('%Y-%m-%d') +
                ' 23:59:59'))

        return queryset
예제 #5
0
def list_staffs(request):
    """
        API get list Staff to select \n
        Parameters for this api : Có thể bỏ trống hoặc không gửi lên
        - email -- text
        - team_id -- number
        - status -- number in {-1,1}
        - is_free -- true/false
    """

    queryset = Staff.objects.values('id', 'email', 'full_name')

    if request.user.is_superuser is False:
        staffs = get_staffs_viewable_queryset(request.user)
        queryset = queryset.filter(pk__in=staffs)

    email = request.GET.get('email', None)
    team_id = request.GET.get('team_id', None)
    status = request.GET.get('status', None)
    is_free = request.GET.get('is_free', None)

    if email is not None and email != '':
        queryset = queryset.filter(
            Q(email__icontains=email) | Q(full_name__icontains=email))
    if status is not None and status != '':
        queryset = queryset.filter(status=status)
    if is_free is not None and is_free == 'true':
        queryset = queryset.filter(team=None)
    if team_id is not None and team_id != '':
        queryset = queryset.filter(team_id=team_id)

    queryset = queryset.order_by('email')[0:settings.PAGINATE_BY]

    data = [{
        'id': staff['id'],
        'email': staff['full_name'] + ' - ' + staff['email']
    } for staff in queryset]

    return successful_response(data)
예제 #6
0
def get_queryset_shop_list(request, export_data=False):
    status = request.query_params.get('status', None)

    shop_obj = Shop
    if not export_data:
        shop_obj = ShopFullData

    if status is not None and status != '':
        if status == '0':
            queryset = shop_obj.objects.shop_active().filter(
                Q(street__isnull=True) | Q(street=''))
        elif status == '1':
            queryset = shop_obj.objects.shop_disable()
        elif status == '2':
            shop_caring_lists = StaffCare.objects.filter(
                type=StaffCareType.STAFF_SHOP).values('shop')
            queryset = shop_obj.objects.shop_active().filter(~Q(
                pk__in=shop_caring_lists))
        else:
            if status == '3':
                shop_lists = ShopCube.objects.number_of_tran_this_week(
                    value=1).values('shop_id')
            elif status == '4':
                shop_lists = ShopCube.objects.number_of_tran_this_week(
                    value=2).values('shop_id')
            elif status == '5':
                shop_lists = ShopCube.objects.number_of_tran_this_week(
                    value=3).values('shop_id')
            else:
                shop_lists = ShopCube.objects.number_of_tran_this_week(
                    value=0).values('shop_id')
            queryset = shop_obj.objects.shop_active().filter(pk__in=shop_lists)
    else:
        queryset = shop_obj.objects.shop_active()

    if request.user.is_superuser is False:
        if request.user.is_area_manager or request.user.is_sale_admin:
            if request.user.is_manager_outside_vnpay:
                shops = get_shops_viewable_queryset(request.user)
                queryset = queryset.filter(pk__in=shops)
            else:
                provinces_viewable = get_provinces_viewable_queryset(
                    request.user)
                cross_assign_status = request.query_params.get(
                    'cross_assign_status', None)
                if cross_assign_status is not None and cross_assign_status != '':
                    if cross_assign_status == '0':
                        staff_viewable = get_staffs_viewable_queryset(
                            request.user)
                        shop_ids = StaffCare.objects.filter(staff__in=staff_viewable, type=StaffCareType.STAFF_SHOP) \
                            .values('shop_id')
                        queryset = queryset.filter(pk__in=shop_ids).exclude(
                            province__in=provinces_viewable)
                    if cross_assign_status == '1':
                        staff_viewable = get_staffs_viewable_queryset(
                            request.user)
                        shop_ids = StaffCare.objects.filter(type=StaffCareType.STAFF_SHOP) \
                            .exclude(staff__in=staff_viewable).values('shop_id')
                        queryset = queryset.filter(
                            pk__in=shop_ids, province__in=provinces_viewable)
                    if cross_assign_status == '2':
                        staff_viewable = get_staffs_viewable_queryset(
                            request.user)
                        shop_id_can_view = StaffCare.objects.filter(staff__in=staff_viewable,
                                                                    type=StaffCareType.STAFF_SHOP) \
                            .values('shop_id')
                        shop_id_can_not_view = StaffCare.objects.filter(type=StaffCareType.STAFF_SHOP) \
                            .exclude(staff__in=staff_viewable).values('shop_id')
                        queryset = queryset.filter(
                            (Q(pk__in=shop_id_can_not_view)
                             & Q(province__in=provinces_viewable))
                            | (Q(pk__in=shop_id_can_view)
                               & ~Q(province__in=provinces_viewable)))
                else:
                    queryset = queryset.filter(
                        province_id__in=provinces_viewable)
        else:
            shops = get_shops_viewable_queryset(request.user)
            queryset = queryset.filter(pk__in=shops)

    code = request.query_params.get('code', None)
    merchant_id = request.query_params.get('merchant_id', None)
    team_id = request.query_params.get('team_id', None)
    staff_id = request.query_params.get('staff_id', None)
    area_id = request.query_params.get('area_id', None)
    province_id = request.query_params.get('province_id', None)
    district_id = request.query_params.get('district_id', None)
    ward_id = request.query_params.get('ward_id', None)
    from_date = request.query_params.get('from_date', None)
    to_date = request.query_params.get('to_date', None)

    if code is not None and code != '':
        code = format_string(code)
        queryset = queryset.filter(
            Q(code__icontains=code) | Q(name__icontains=code))

    if merchant_id is not None and merchant_id != '':
        queryset = queryset.filter(merchant_id=merchant_id)

    if team_id is not None and team_id != '':
        staffs = Staff.objects.filter(team=team_id)
        shop_ids = StaffCare.objects.filter(
            staff__in=staffs, type=StaffCareType.STAFF_SHOP).values('shop_id')
        queryset = queryset.filter(pk__in=shop_ids)

    if staff_id is not None and staff_id != '':
        shop_ids = StaffCare.objects.filter(
            staff=staff_id, type=StaffCareType.STAFF_SHOP).values('shop_id')
        queryset = queryset.filter(pk__in=shop_ids)

    if area_id is not None and area_id != '':
        if area_id.isdigit():
            area = Area.objects.get(pk=int(area_id))
            provinces = area.get_provinces()
            queryset = queryset.filter(province_id__in=provinces)

    if province_id is not None and province_id != '':
        queryset = queryset.filter(province_id=province_id)

    if district_id is not None and district_id != '':
        queryset = queryset.filter(district_id=district_id)

    if ward_id is not None and ward_id != '':
        queryset = queryset.filter(wards_id=ward_id)

    if from_date is not None and from_date != '':
        queryset = queryset.filter(created_date__gte=datetime.strptime(
            from_date, '%d/%m/%Y').strftime('%Y-%m-%d %H:%M:%S'))

    if to_date is not None and to_date != '':
        queryset = queryset.filter(created_date__lte=(
            datetime.strptime(to_date, '%d/%m/%Y').strftime('%Y-%m-%d') +
            ' 23:59:59'))
    return queryset.order_by('-id')