Exemple #1
0
class EventSerializer(serializers.ModelSerializer):
    created_by = ProfileSerializer()
    assigned_to = ProfileSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    teams = TeamsSerializer(read_only=True, many=True)
    event_attachment = AttachmentsSerializer(read_only=True, many=True)
    event_comments = CommentSerializer(read_only=True, many=True)
    org = OrganizationSerializer()

    class Meta:
        model = Event
        fields = (
            "id",
            "name",
            "event_type",
            "status",
            "is_active",
            "disabled",
            "start_date",
            "start_time",
            "end_date",
            "end_time",
            "description",
            "date_of_meeting",
            "created_by",
            "created_on",
            "contacts",
            "teams",
            "assigned_to",
            "event_attachment",
            "event_comments",
            "org"
        )
class CaseSerializer(serializers.ModelSerializer):
    account = AccountSerializer()
    contacts = ContactSerializer(read_only=True, many=True)
    assigned_to = ProfileSerializer(read_only=True, many=True)
    created_by = ProfileSerializer(read_only=True)
    teams = TeamsSerializer(read_only=True, many=True)
    org = OrganizationSerializer()

    class Meta:
        model = Case
        fields = (
            "id",
            "name",
            "status",
            "priority",
            "case_type",
            "closed_on",
            "description",
            "created_by",
            "created_on",
            "is_active",
            "account",
            "contacts",
            "teams",
            "assigned_to",
            "org",
            "created_on_arrow",
        )
Exemple #3
0
class CaseSerializer(serializers.ModelSerializer):
    account = AccountSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    assigned_to = UserSerializer(read_only=True, many=True)
    created_by = UserSerializer(read_only=True)
    teams = TeamsSerializer(read_only=True, many=True)
    company = CompanySerializer()
    get_team_users = UserSerializer(read_only=True, many=True)
    get_team_and_assigned_users = UserSerializer(read_only=True, many=True)
    get_assigned_users_not_in_teams = UserSerializer(read_only=True, many=True)

    class Meta:
        model = Case
        fields = (
            'id',
            'name',
            'status',
            'priority',
            'case_type',
            'account',
            'contacts',
            'closed_on',
            'description',
            'assigned_to',
            'created_by',
            'created_on',
            'is_active',
            'teams',
            'company',
            'get_team_users',
            'get_team_and_assigned_users',
            "get_assigned_users_not_in_teams",
            "created_on_arrow",
        )
class CaseSerializer(serializers.ModelSerializer):
    account = AccountSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    assigned_to = UserSerializer(read_only=True, many=True)
    created_by = UserSerializer(read_only=True)
    teams = TeamsSerializer(read_only=True, many=True)
    company = CompanySerializer()
    get_team_users = UserSerializer(read_only=True, many=True)
    get_team_and_assigned_users = UserSerializer(read_only=True, many=True)
    get_assigned_users_not_in_teams = UserSerializer(read_only=True, many=True)

    class Meta:
        model = Case
        fields = (
            "id",
            "name",
            "status",
            "priority",
            "case_type",
            "account",
            "contacts",
            "closed_on",
            "description",
            "assigned_to",
            "created_by",
            "created_on",
            "is_active",
            "teams",
            "company",
            "get_team_users",
            "get_team_and_assigned_users",
            "get_assigned_users_not_in_teams",
            "created_on_arrow",
        )
Exemple #5
0
class TaskSerializer(serializers.ModelSerializer):
    created_by = ProfileSerializer()
    assigned_to = ProfileSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    teams = TeamsSerializer(read_only=True, many=True)
    task_attachment = AttachmentsSerializer(read_only=True, many=True)
    task_comments = CommentSerializer(read_only=True, many=True)

    class Meta:
        model = Task
        fields = (
            "id",
            "title",
            "status",
            "priority",
            "due_date",
            "account",
            "created_by",
            "created_on",
            "contacts",
            "teams",
            "assigned_to",
            "task_attachment",
            "task_comments",
        )
Exemple #6
0
    def get(self, request, format=None):

        accounts = Account.objects.filter(status="open",
                                          company=request.company)
        contacts = Contact.objects.filter(company=request.company)
        leads = Lead.objects.filter(company=request.company).exclude(
            Q(status="converted") | Q(status="closed"))
        opportunities = Opportunity.objects.filter(company=request.company)

        if self.request.user.role == "ADMIN" or self.request.user.is_superuser:
            pass
        else:
            accounts = accounts.filter(
                Q(assigned_to__id__in=[self.request.user.id])
                | Q(created_by=self.request.user.id))
            contacts = contacts.filter(
                Q(assigned_to__id__in=[self.request.user.id])
                | Q(created_by=self.request.user.id))
            leads = leads.filter(
                Q(assigned_to__id__in=[self.request.user.id])
                | Q(created_by=self.request.user.id)).exclude(status="closed")
            opportunities = opportunities.filter(
                Q(assigned_to__id__in=[self.request.user.id])
                | Q(created_by=self.request.user.id))
        context = {}
        context["accounts_count"] = accounts.count()
        context["contacts_count"] = contacts.count()
        context["leads_count"] = leads.count()
        context["opportunities_count"] = opportunities.count()
        context["accounts"] = AccountSerializer(accounts, many=True).data
        context["contacts"] = ContactSerializer(contacts, many=True).data
        context["leads"] = LeadSerializer(leads, many=True).data
        context["opportunities"] = OpportunitySerializer(opportunities,
                                                         many=True).data
        return Response(context, status=status.HTTP_200_OK)
Exemple #7
0
    def get_context_data(self, **kwargs):
        params = (self.request.query_params
                  if len(self.request.data) == 0 else self.request.data)
        queryset = self.model.objects.filter(company=self.request.company)
        accounts = Account.objects.filter(company=self.request.company)
        contacts = Contact.objects.filter(company=self.request.company)
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(assigned_to__in=[self.request.user])
                | Q(created_by=self.request.user))
            accounts = accounts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()

        request_post = params
        if request_post:
            if request_post.get("title"):
                queryset = queryset.filter(
                    title__icontains=request_post.get("title"))
            if request_post.get("status"):
                queryset = queryset.filter(status=request_post.get("status"))
            if request_post.get("priority"):
                queryset = queryset.filter(
                    priority=request_post.get("priority"))
        context = {}
        search = False
        if (params.get("title") or params.get("status")
                or params.get("priority")):
            search = True
        context["search"] = search

        if search:
            context["tasks"] = TaskSerializer(queryset.distinct(),
                                              many=True).data
            return context

        context["tasks"] = TaskSerializer(queryset.distinct(), many=True).data
        context["status"] = STATUS_CHOICES
        context["priority"] = PRIORITY_CHOICES
        users = []
        if self.request.user.role == "ADMIN" or self.request.user.is_superuser:
            users = User.objects.filter(
                is_active=True, company=self.request.company).order_by("email")
        elif self.request.user.google.all():
            users = []
        else:
            users = User.objects.filter(
                role="ADMIN", company=self.request.company).order_by("email")
        context["users"] = UserSerializer(users, many=True).data
        if self.request.user == "ADMIN":
            context["teams_list"] = TeamsSerializer(
                Teams.objects.filter(company=self.request.company),
                many=True).data
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
Exemple #8
0
    def get_context_data(self, **kwargs):
        params = (self.request.query_params
                  if len(self.request.data) == 0 else self.request.data)
        queryset = self.model.objects.filter(
            org=self.request.org).order_by('-id')
        accounts = Account.objects.filter(org=self.request.org)
        contacts = Contact.objects.filter(org=self.request.org)
        if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(created_by=self.request.profile)
                | Q(assigned_to=self.request.profile)).distinct()
            accounts = accounts.filter(
                Q(created_by=self.request.profile)
                | Q(assigned_to=self.request.profile)).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.profile)
                | Q(assigned_to=self.request.profile)).distinct()

        if params:
            if params.get("name"):
                queryset = queryset.filter(name__icontains=params.get("name"))
            if params.get("account"):
                queryset = queryset.filter(account=params.get("account"))
            if params.get("stage"):
                queryset = queryset.filter(stage__contains=params.get("stage"))
            if params.get("lead_source"):
                queryset = queryset.filter(
                    lead_source__contains=params.get("lead_source"))
            if params.get("tags"):
                queryset = queryset.filter(
                    tags__in=json.loads(params.get("tags"))).distinct()

        context = {}
        results_opportunities = self.paginate_queryset(queryset.distinct(),
                                                       self.request,
                                                       view=self)
        opportunities = OpportunitySerializer(results_opportunities,
                                              many=True).data
        if results_opportunities:
            offset = queryset.filter(
                id__gte=results_opportunities[-1].id).count()
            if offset == queryset.count():
                offset = None
        else:
            offset = 0
        context.update({
            "opportunities_count": self.count,
            "offset": offset,
        })
        context["opportunities"] = opportunities
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        context['tags'] = TagsSerailizer(Tags.objects.filter(), many=True).data
        context["stage"] = STAGES
        context["lead_source"] = SOURCES
        context["currency"] = CURRENCY_CODES

        return context
Exemple #9
0
    def get_context_data(self, **kwargs):
        params = (
            self.request.query_params
            if len(self.request.data) == 0
            else self.request.data
        )
        queryset = self.model.objects.filter(
            org=self.request.org).order_by('-id')
        accounts = Account.objects.filter(org=self.request.org)
        contacts = Contact.objects.filter(org=self.request.org)
        if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
            queryset = queryset.filter(
                Q(assigned_to__in=[self.request.profile]) | Q(
                    created_by=self.request.profile)
            )
            accounts = accounts.filter(
                Q(created_by=self.request.profile) | Q(
                    assigned_to=self.request.profile)
            ).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.profile) | Q(
                    assigned_to=self.request.profile)
            ).distinct()

        if params:
            if params.get("title"):
                queryset = queryset.filter(
                    title__icontains=params.get("title"))
            if params.get("status"):
                queryset = queryset.filter(status=params.get("status"))
            if params.get("priority"):
                queryset = queryset.filter(
                    priority=params.get("priority"))
        context = {}
        results_tasks = self.paginate_queryset(
            queryset.distinct(), self.request, view=self
        )
        tasks = TaskSerializer(results_tasks, many=True).data
        if results_tasks:
            offset = queryset.filter(id__gte=results_tasks[-1].id).count()
            if offset == queryset.count():
                offset = None
        else:
            offset = 0
        context.update(
            {
                "tasks_count": self.count,
                "offset": offset,
            }
        )
        context["tasks"] = tasks
        context["status"] = STATUS_CHOICES
        context["priority"] = PRIORITY_CHOICES
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
Exemple #10
0
class LeadSerializer(serializers.ModelSerializer):
    # user = UserSerializer()
    assigned_to = UserSerializer(read_only=True, many=True)
    created_by = UserSerializer()
    tags = TagsSerailizer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)

    class Meta:
        model = Lead
        # fields = ‘__all__’
        fields = (
            'id',
            "title",
            "first_name",
            "last_name",
            "email",
            "phone",
            "status",
            "source",
            "address_line",
            "street",
            "city",
            "state",
            "postcode",
            "country",
            "website",
            "description",
            "assigned_to",
            "account_name",
            "opportunity_amount",
            "created_by",
            "created_on",
            "is_active",
            "enquery_type",
            "tags",
            "contacts",
            "created_from_site",
            "teams",
            "company",
            # "phone_raw_input",
            # "created_on_arrow",
            # "get_team_users",
            # "get_team_and_assigned_users",
            # "get_assigned_users_not_in_teams",
        )
Exemple #11
0
class AccountSerializer(serializers.ModelSerializer):
    created_by = UserSerializer()
    lead = LeadSerializer()
    company = CompanySerializer()
    tags = TagsSerailizer(read_only=True, many=True)
    assigned_to = UserSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    teams = TeamsSerializer(read_only=True, many=True)

    class Meta:
        model = Account
        # fields = ‘__all__’
        fields = ('id', "name", "email", "phone", "industry",
                  "billing_address_line", "billing_street", "billing_city",
                  "billing_state", "billing_postcode", "billing_country",
                  "website", "description", "created_by", "created_on",
                  "is_active", "tags", "status", "lead", "contact_name",
                  "contacts", "assigned_to", "teams", "company")
Exemple #12
0
 def get(self, request, pk, format=None):
     profile_obj = self.get_object(pk)
     if (self.request.profile.role != "ADMIN"
             and not self.request.profile.is_admin
             and self.request.profile.id != profile_obj.id):
         return Response(
             {
                 "error": True,
                 "errors": "Permission Denied"
             },
             status=status.HTTP_403_FORBIDDEN,
         )
     if profile_obj.org != request.org:
         return Response(
             {
                 "error": True,
                 "errors": "User company doesnot match with header...."
             },
             status=status.HTTP_403_FORBIDDEN,
         )
     assigned_data = Profile.objects.filter(org=request.org,
                                            is_active=True).values(
                                                'id', 'user__first_name')
     context = {}
     context["profile_obj"] = ProfileSerializer(profile_obj).data
     opportunity_list = Opportunity.objects.filter(assigned_to=profile_obj)
     context["opportunity_list"] = OpportunitySerializer(opportunity_list,
                                                         many=True).data
     contacts = Contact.objects.filter(assigned_to=profile_obj)
     context["contacts"] = ContactSerializer(contacts, many=True).data
     cases = Case.objects.filter(assigned_to=profile_obj)
     context["cases"] = CaseSerializer(cases, many=True).data
     context["assigned_data"] = assigned_data
     comments = profile_obj.user_comments.all()
     context["comments"] = CommentSerializer(comments, many=True).data
     context["countries"] = COUNTRIES
     return Response(
         {
             "error": False,
             "data": context
         },
         status=status.HTTP_200_OK,
     )
Exemple #13
0
class AccountSerializer(serializers.ModelSerializer):
    created_by = ProfileSerializer()
    lead = LeadSerializer()
    org = OrganizationSerializer()
    tags = TagsSerailizer(read_only=True, many=True)
    assigned_to = ProfileSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    teams = TeamsSerializer(read_only=True, many=True)
    account_attachment = AttachmentsSerializer(read_only=True, many=True)

    class Meta:
        model = Account
        # fields = ‘__all__’
        fields = ("id", "name", "email", "phone", "industry",
                  "billing_address_line", "billing_street", "billing_city",
                  "billing_state", "billing_postcode", "billing_country",
                  "website", "description", "account_attachment", "created_by",
                  "created_on", "is_active", "tags", "status", "lead",
                  "contact_name", "contacts", "assigned_to", "teams", "org")
Exemple #14
0
    def get_context_data(self, **kwargs):
        params = (self.request.query_params
                  if len(self.request.data) == 0 else self.request.data)
        queryset = self.model.objects.filter(
            org=self.request.org).order_by('-id')
        contacts = Contact.objects.filter(org=self.request.org)
        if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
            queryset = queryset.filter(
                Q(assigned_to__in=[self.request.profile])
                | Q(created_by=self.request.profile))
            contacts = contacts.filter(
                Q(created_by=self.request.profile)
                | Q(assigned_to=self.request.profile)).distinct()

        if params:
            if params.get("name"):
                queryset = queryset.filter(name__icontains=params.get("name"))
            if params.get("created_by"):
                queryset = queryset.filter(created_by=params.get("created_by"))
            if params.getlist("assigned_users"):
                queryset = queryset.filter(assigned_to__id__in=json.loads(
                    params.get("assigned_users")))
            if params.get("date_of_meeting"):
                queryset = queryset.filter(
                    date_of_meeting=params.get("date_of_meeting"))
        context = {}
        results_events = self.paginate_queryset(queryset,
                                                self.request,
                                                view=self)
        events = EventSerializer(results_events, many=True).data
        if results_events:
            offset = queryset.filter(id__gte=results_events[-1].id).count()
            if offset == queryset.count():
                offset = None
        else:
            offset = 0
        context.update({"events_count": self.count, "offset": offset})
        context["events"] = events
        context["recurring_days"] = WEEKDAYS
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
 def get(self, request, pk, format=None):
     user_obj = self.get_object(pk)
     users_data = []
     for each in User.objects.all():
         assigned_dict = {}
         assigned_dict["id"] = each.id
         assigned_dict["name"] = each.username
         users_data.append(assigned_dict)
     context = {}
     context["user_obj"] = UserSerializer(user_obj).data
     opportunity_list = Opportunity.objects.filter(assigned_to=user_obj)
     context["opportunity_list"] = OpportunitySerializer(opportunity_list,
                                                         many=True).data
     contacts = Contact.objects.filter(assigned_to=user_obj)
     context["contacts"] = ContactSerializer(contacts, many=True).data
     cases = Case.objects.filter(assigned_to=user_obj)
     context["cases"] = CaseSerializer(cases, many=True).data
     context["assigned_data"] = users_data
     comments = user_obj.user_comments.all()
     context["comments"] = CommentSerializer(comments, many=True).data
     return Response({"error": False, "data": context})
Exemple #16
0
class OpportunitySerializer(serializers.ModelSerializer):
    account = AccountSerializer()
    closed_by = UserSerializer()
    created_by = UserSerializer()
    company = CompanySerializer()
    tags = TagsSerializer(read_only=True, many=True)
    assigned_to = UserSerializer(read_only=True, many=True)
    contacts = ContactSerializer(read_only=True, many=True)
    teams = TeamsSerializer(read_only=True, many=True)
    opportunity_attachment = AttachmentsSerializer(read_only=True, many=True)

    class Meta:
        model = Opportunity
        # fields = ‘__all__’
        fields = (
            "id",
            "name",
            "stage",
            "currency",
            "amount",
            "lead_source",
            "probability",
            "contacts",
            "closed_by",
            "closed_on",
            "description",
            "assigned_to",
            "created_by",
            "created_on",
            "is_active",
            "tags",
            "opportunity_attachment",
            "teams",
            "company",
            "created_on_arrow",
            "account",
            # "get_team_users",
            # "get_team_and_assigned_users",
            # "get_assigned_users_not_in_teams",
        )
Exemple #17
0
 def get(self, request, pk, format=None):
     user_obj = self.get_object(pk)
     if (self.request.user.role != "ADMIN"
             and not self.request.user.is_superuser
             and self.request.user.id != user_obj.id):
         return Response(
             {
                 "error": True,
                 "errors": "Permission Denied"
             },
             status=status.HTTP_403_FORBIDDEN,
         )
     users_data = []
     for each in User.objects.all():
         assigned_dict = {}
         assigned_dict["id"] = each.id
         assigned_dict["name"] = each.username
         users_data.append(assigned_dict)
     context = {}
     context["user_obj"] = UserSerializer(user_obj).data
     opportunity_list = Opportunity.objects.filter(assigned_to=user_obj)
     context["opportunity_list"] = OpportunitySerializer(opportunity_list,
                                                         many=True).data
     contacts = Contact.objects.filter(assigned_to=user_obj)
     context["contacts"] = ContactSerializer(contacts, many=True).data
     cases = Case.objects.filter(assigned_to=user_obj)
     context["cases"] = CaseSerializer(cases, many=True).data
     context["assigned_data"] = users_data
     comments = user_obj.user_comments.all()
     context["comments"] = CommentSerializer(comments, many=True).data
     return Response(
         {
             "error": False,
             "data": context
         },
         status=status.HTTP_200_OK,
     )
Exemple #18
0
    def get_context_data(self, **kwargs):
        params = (self.request.query_params
                  if len(self.request.data) == 0 else self.request.data)
        queryset = self.model.objects.all()
        accounts = Account.objects.all()
        contacts = Contact.objects.all()
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(assigned_to__in=[self.request.user])
                | Q(created_by=self.request.user))
            accounts = accounts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()

        request_post = params
        if request_post:
            if request_post.get("title"):
                queryset = queryset.filter(
                    title__icontains=request_post.get("title"))
            if request_post.get("status"):
                queryset = queryset.filter(status=request_post.get("status"))
            if request_post.get("priority"):
                queryset = queryset.filter(
                    priority=request_post.get("priority"))
        context = {}
        search = False
        if params.get("title") or params.get("status") or params.get(
                "priority"):
            search = True
        context["search"] = search
        results_tasks = self.paginate_queryset(queryset.distinct(),
                                               self.request,
                                               view=self)
        tasks = TaskSerializer(results_tasks, many=True).data
        context["per_page"] = 10
        context.update({
            "tasks_count": self.count,
            "next": self.get_next_link(),
            "previous": self.get_previous_link(),
            "page_number": int(self.offset / 10) + 1,
        })
        context["tasks"] = tasks
        context["status"] = STATUS_CHOICES
        context["priority"] = PRIORITY_CHOICES
        users = []
        if self.request.user.role == "ADMIN" or self.request.user.is_superuser:
            users = User.objects.filter(is_active=True, ).order_by("email")
        elif self.request.user.google.all():
            users = []
        else:
            users = User.objects.filter(role="ADMIN", ).order_by("email")
        context["users"] = UserSerializer(users, many=True).data
        if self.request.user == "ADMIN":
            context["teams_list"] = TeamsSerializer(Teams.objects.all(),
                                                    many=True).data
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
    def get(self, request, pk, format=None):
        context = {}
        context["account_obj"] = AccountSerializer(self.account).data
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            if not ((self.request.user == self.account.created_by) or
                    (self.request.user in self.account.assigned_to.all())):
                raise PermissionDenied

        comment_permission = (True if
                              (self.request.user == self.account.created_by
                               or self.request.user.is_superuser or
                               self.request.user.role == "ADMIN") else False)

        if self.request.user.is_superuser or self.request.user.role == "ADMIN":
            users_mention = list(
                User.objects.filter(
                    is_active=True,
                    company=self.request.company,
                ).values("username"))
        elif self.request.user != self.account.created_by:
            if self.account.created_by:
                users_mention = [{
                    "username": self.account.created_by.username
                }]
            else:
                users_mention = []
        else:
            users_mention = []

        context.update({
            "comments":
            CommentSerializer(self.account.accounts_comments.all(),
                              many=True).data,
            "attachments":
            AttachmentsSerializer(self.account.account_attachment.all(),
                                  many=True).data,
            "opportunity_list":
            OpportunitySerializer(
                Opportunity.objects.filter(account=self.account),
                many=True).data,
            "contacts":
            ContactSerializer(self.account.contacts.all(), many=True).data,
            "users":
            UserSerializer(
                User.objects.filter(
                    is_active=True,
                    company=self.request.company,
                ).order_by("email"),
                many=True,
            ).data,
            "cases":
            CaseSerializer(Case.objects.filter(account=self.account),
                           many=True).data,
            "stages":
            STAGES,
            "sources":
            SOURCES,
            "countries":
            COUNTRIES,
            "currencies":
            CURRENCY_CODES,
            "case_types":
            CASE_TYPE,
            "case_priority":
            PRIORITY_CHOICE,
            "case_status":
            STATUS_CHOICE,
            "comment_permission":
            comment_permission,
            "tasks":
            TaskSerializer(self.account.accounts_tasks.all(), many=True).data,
            "invoices":
            InvoiceSerailizer(self.account.accounts_invoices.all(),
                              many=True).data,
            "emails":
            EmailSerailizer(self.account.sent_email.all(), many=True).data,
            "users_mention":
            users_mention,
        })
        return Response(context)
Exemple #20
0
    def get_context_data(self, **kwargs):
        params = (self.request.query_params
                  if len(self.request.data) == 0 else self.request.data)
        queryset = self.model.objects.filter(company=self.request.company)
        accounts = Account.objects.filter(company=self.request.company)
        contacts = Contact.objects.filter(company=self.request.company)
        users = User.objects.filter(is_active=True,
                                    company=self.request.company)
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()
            accounts = accounts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.user)
                | Q(assigned_to=self.request.user)).distinct()
            users = users.filter(role="ADMIN")

        if params:
            if params.get("name"):
                queryset = queryset.filter(name__icontains=params.get("name"))
            if params.get("status"):
                queryset = queryset.filter(status=params.get("status"))
            if params.get("priority"):
                queryset = queryset.filter(priority=params.get("priority"))
            if params.get("account"):
                queryset = queryset.filter(account=params.get("account"))

        context = {}
        search = False
        if (params.get("name") or params.get("status")
                or params.get("priority") or params.get("account")):
            search = True
        context["search"] = search

        results_cases = self.paginate_queryset(queryset,
                                               self.request,
                                               view=self)
        cases = CaseSerializer(results_cases, many=True).data

        context["per_page"] = 10
        context.update({
            "cases_count": self.count,
            "next": self.get_next_link(),
            "previous": self.get_previous_link(),
            "page_number": int(self.offset / 10) + 1,
        })
        if search:
            context["cases"] = cases
            return context
        context["cases"] = cases
        context["users"] = UserSerializer(users, many=True).data
        context["status"] = STATUS_CHOICE
        context["priority"] = PRIORITY_CHOICE
        context["type_of_case"] = CASE_TYPE
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        if self.request.user == "ADMIN":
            context["teams_list"] = TeamsSerializer(
                Teams.objects.filter(company=self.request.company),
                many=True).data
        return context
Exemple #21
0
    def get_context_data(self, **kwargs):
        params = (
            self.request.query_params
            if len(self.request.data) == 0
            else self.request.data
        )
        queryset = self.model.objects.all()
        contacts = Contact.objects.all()
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(assigned_to__in=[self.request.user]) | Q(created_by=self.request.user)
            )
            contacts = contacts.filter(
                Q(created_by=self.request.user) | Q(assigned_to=self.request.user)
            ).distinct()

        if params:
            if params.get("name"):
                queryset = queryset.filter(name__icontains=params.get("name"))
            if params.get("created_by"):
                queryset = queryset.filter(created_by=params.get("created_by"))
            if params.getlist("assigned_users"):
                queryset = queryset.filter(
                    assigned_to__id__in=json.loads(params.get("assigned_users"))
                )
            if params.get("date_of_meeting"):
                queryset = queryset.filter(
                    date_of_meeting=params.get("date_of_meeting")
                )
        context = {}
        search = False
        if (
            params.get("name")
            or params.get("created_by")
            or params.get("assigned_users")
            or params.get("date_of_meeting")
        ):
            search = True
        context["search"] = search
        results_events = self.paginate_queryset(queryset, self.request, view=self)
        events = EventSerializer(results_events, many=True).data

        context["per_page"] = 10
        context.update(
            {
                "events_count": self.count,
                "next": self.get_next_link(),
                "previous": self.get_previous_link(),
                "page_number": int(self.offset / 10) + 1,
            }
        )

        if search:
            context["events"] = events
            return context

        context["events"] = events
        users = []
        if self.request.user.role == "ADMIN" or self.request.user.is_superuser:
            users = User.objects.filter(
                is_active=True,
            ).order_by("email")
        else:
            users = User.objects.filter(role="ADMIN").order_by("email")
        context["recurring_days"] = WEEKDAYS
        context["users"] = UserSerializer(users, many=True).data
        if self.request.user == "ADMIN":
            context["teams_list"] = TeamsSerializer(Teams.objects.all(), many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
Exemple #22
0
    def get_context_data(self, **kwargs):
        params = (
            self.request.query_params
            if len(self.request.data) == 0
            else self.request.data
        )
        queryset = self.model.objects.filter(company=self.request.company)
        accounts = Account.objects.filter(company=self.request.company)
        contacts = Contact.objects.filter(company=self.request.company)
        if self.request.user.role != "ADMIN" and not self.request.user.is_superuser:
            queryset = queryset.filter(
                Q(created_by=self.request.user) | Q(assigned_to=self.request.user)
            ).distinct()
            accounts = accounts.filter(
                Q(created_by=self.request.user) | Q(assigned_to=self.request.user)
            ).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.user) | Q(assigned_to=self.request.user)
            ).distinct()

        
        if params:
            request_post = params
            if request_post.get("name"):
                queryset = queryset.filter(
                    name__icontains=request_post.get("name")
                )
            if request_post.get("account"):
                queryset = queryset.filter(
                    account=request_post.get("account")
                )
            if request_post.get("stage"):
                queryset = queryset.filter(
                    stage__contains=request_post.get("stage")
                )
            if request_post.get("lead_source"):
                queryset = queryset.filter(
                    lead_source__contains=request_post.get("lead_source")
                )
            if request_post.get("tags"):
                queryset = queryset.filter(
                    tags__in=json.loads(request_post.get("tags"))
                ).distinct()

        context = {}
        search = False
        if (
            params.get("name")
            or params.get("account")
            or params.get("stage")
            or params.get("lead_source")
            or params.get("tags")
        ):
            search = True

        context["search"] = search
        opportunities = OpportunitySerializer(
            queryset, many=True
        ).data

        context["opportunities"] = opportunities  
        context["users"] = UserSerializer(
            User.objects.filter(is_active=True, company=self.request.company).order_by("email"), many=True
        ).data   
        tag_ids = list(set(Opportunity.objects.filter(
            company=self.request.company).values_list("tags", flat=True)))
        context["tags"] = TagsSerializer(
            Tags.objects.filter(id__in=tag_ids), many=True
        ).data
        context["accounts_list"] = AccountSerializer(
            accounts, many=True
        ).data
        context["contacts_list"] = ContactSerializer(
            contacts, many=True
        ).data
        if self.request.user == "ADMIN":
            context["teams_list"] = TeamsSerializer(
                Teams.objects.filter(company=self.request.company), many=True
            ).data
        context["stage"] = STAGES
        context["lead_source"] = SOURCES
        context["currency"] = CURRENCY_CODES        

        return context
Exemple #23
0
    def get_context_data(self, **kwargs):
        params = (
            self.request.query_params
            if len(self.request.data) == 0
            else self.request.data
        )
        queryset = self.model.objects.filter(
            org=self.request.org).order_by('-id')
        accounts = Account.objects.filter(org=self.request.org).order_by('-id')
        contacts = Contact.objects.filter(org=self.request.org).order_by('-id')
        profiles = Profile.objects.filter(
            is_active=True, org=self.request.org)
        if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
            queryset = queryset.filter(
                Q(created_by=self.request.profile) | Q(
                    assigned_to=self.request.profile)
            ).distinct()
            accounts = accounts.filter(
                Q(created_by=self.request.profile) | Q(
                    assigned_to=self.request.profile)
            ).distinct()
            contacts = contacts.filter(
                Q(created_by=self.request.profile) | Q(
                    assigned_to=self.request.profile)
            ).distinct()
            profiles = profiles.filter(role="ADMIN")

        if params:
            if params.get("name"):
                queryset = queryset.filter(name__icontains=params.get("name"))
            if params.get("status"):
                queryset = queryset.filter(status=params.get("status"))
            if params.get("priority"):
                queryset = queryset.filter(priority=params.get("priority"))
            if params.get("account"):
                queryset = queryset.filter(account=params.get("account"))

        context = {}

        results_cases = self.paginate_queryset(
            queryset, self.request, view=self)
        cases = CaseSerializer(results_cases, many=True).data

        if results_cases:
            offset = queryset.filter(id__gte=results_cases[-1].id).count()
            if offset == queryset.count():
                offset = None
        else:
            offset = 0
        context.update(
            {
                "cases_count": self.count,
                "offset": offset,
            }
        )
        context["cases"] = cases
        context["status"] = STATUS_CHOICE
        context["priority"] = PRIORITY_CHOICE
        context["type_of_case"] = CASE_TYPE
        context["accounts_list"] = AccountSerializer(accounts, many=True).data
        context["contacts_list"] = ContactSerializer(contacts, many=True).data
        return context
Exemple #24
0
    def get(self, request, pk, format=None):
        self.cases = self.get_object(pk=pk)
        if self.cases.org != request.org:
            return Response(
                {"error": True, "errors": "User company doesnot match with header...."},
                status=status.HTTP_403_FORBIDDEN,
            )
        context = {}
        context["cases_obj"] = CaseSerializer(self.cases).data
        if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
            if not (
                (self.request.profile == self.cases.created_by)
                or (self.request.profile in self.cases.assigned_to.all())
            ):
                return Response(
                    {
                        "error": True,
                        "errors": "You don't have Permission to perform this action",
                    },
                    status=status.HTTP_403_FORBIDDEN,
                )

        comment_permission = False

        if (
            self.request.profile == self.cases.created_by
            or self.request.profile.is_admin
            or self.request.profile.role == "ADMIN"
        ):
            comment_permission = True

        if self.request.profile.is_admin or self.request.profile.role == "ADMIN":
            users_mention = list(
                Profile.objects.filter(
                    is_active=True, org=self.request.org
                ).values("user__username")
            )
        elif self.request.profile != self.cases.created_by:
            if self.cases.created_by:
                users_mention = [
                    {"username": self.cases.created_by.user.username}]
            else:
                users_mention = []
        else:
            users_mention = []

        attachments = Attachments.objects.filter(
            case=self.cases).order_by("-id")
        comments = Comment.objects.filter(case=self.cases).order_by("-id")

        context.update(
            {
                "attachments": AttachmentsSerializer(attachments, many=True).data,
                "comments": CommentSerializer(comments, many=True).data,
                "contacts": ContactSerializer(
                    self.cases.contacts.all(), many=True
                ).data,
                "status": STATUS_CHOICE,
                "priority": PRIORITY_CHOICE,
                "type_of_case": CASE_TYPE,
                "comment_permission": comment_permission,
                "users_mention": users_mention,
            }
        )
        return Response(context)
Exemple #25
0
    def get(self, request, pk, format=None):
        self.account = self.get_object(pk=pk)
        if self.account.org != request.org:
            return Response(
                {
                    "error": True,
                    "errors": "User company doesnot match with header...."
                },
                status=status.HTTP_404_NOT_FOUND,
            )
        context = {}
        context["account_obj"] = AccountSerializer(self.account).data
        if self.request.profile.role != "ADMIN" and not self.request.profile.is_admin:
            if not ((self.request.profile == self.account.created_by) or
                    (self.request.profile in self.account.assigned_to.all())):
                return Response(
                    {
                        "error":
                        True,
                        "errors":
                        "You do not have Permission to perform this action",
                    },
                    status=status.HTTP_403_FORBIDDEN,
                )

        comment_permission = False
        if (self.request.profile == self.account.created_by
                or self.request.profile.is_admin
                or self.request.profile.role == "ADMIN"):
            comment_permission = True

        if self.request.profile.is_admin or self.request.profile.role == "ADMIN":
            users_mention = list(
                Profile.objects.filter(
                    is_active=True,
                    org=self.request.org).values("user__username"))
        elif self.request.profile != self.account.created_by:
            if self.account.created_by:
                users_mention = [{
                    "username":
                    self.account.created_by.user.username
                }]
            else:
                users_mention = []
        else:
            users_mention = []
        context.update({
            "attachments":
            AttachmentsSerializer(self.account.account_attachment.all(),
                                  many=True).data,
            "comments":
            CommentSerializer(self.account.accounts_comments.all(),
                              many=True).data,
            "contacts":
            ContactSerializer(self.account.contacts.all(), many=True).data,
            "opportunity_list":
            OpportunitySerializer(
                Opportunity.objects.filter(account=self.account),
                many=True).data,
            "users":
            ProfileSerializer(
                Profile.objects.filter(
                    is_active=True,
                    org=self.request.org).order_by("user__email"),
                many=True,
            ).data,
            "cases":
            CaseSerializer(self.account.accounts_cases.all(), many=True).data,
            "stages":
            STAGES,
            "sources":
            SOURCES,
            "countries":
            COUNTRIES,
            "currencies":
            CURRENCY_CODES,
            "case_types":
            CASE_TYPE,
            "case_priority":
            PRIORITY_CHOICE,
            "case_status":
            STATUS_CHOICE,
            "comment_permission":
            comment_permission,
            "tasks":
            TaskSerializer(self.account.accounts_tasks.all(), many=True).data,
            "invoices":
            InvoiceSerailizer(self.account.accounts_invoices.all(),
                              many=True).data,
            "emails":
            EmailSerializer(self.account.sent_email.all(), many=True).data,
            "users_mention":
            users_mention,
        })
        return Response(context)
Exemple #26
0
    def get(self, request, pk, format=None):
        self.opportunity = self.get_object(pk=pk)
        context = {}
        context["opportunity_obj"] = OpportunitySerializer(
            self.opportunity).data
        if self.opportunity.org != request.org:
            return Response(
                {
                    "error": True,
                    "errors": "User company doesnot match with header...."
                },
                status=status.HTTP_403_FORBIDDEN,
            )
        if self.request.profile.role != "ADMIN" and not self.request.user.is_superuser:
            if not (
                (self.request.profile == self.opportunity.created_by) or
                (self.request.profile in self.opportunity.assigned_to.all())):
                return Response(
                    {
                        "error":
                        True,
                        "errors":
                        "You don't have Permission to perform this action",
                    },
                    status=status.HTTP_403_FORBIDDEN,
                )

        comment_permission = False

        if (self.request.profile == self.opportunity.created_by
                or self.request.user.is_superuser
                or self.request.profile.role == "ADMIN"):
            comment_permission = True

        if self.request.user.is_superuser or self.request.profile.role == "ADMIN":
            users_mention = list(
                Profile.objects.filter(
                    is_active=True,
                    org=self.request.org).values("user__username"))
        elif self.request.profile != self.opportunity.created_by:
            if self.opportunity.created_by:
                users_mention = [{
                    "username":
                    self.opportunity.created_by.user.username
                }]
            else:
                users_mention = []
        else:
            users_mention = []

        context.update({
            "comments":
            CommentSerializer(self.opportunity.opportunity_comments.all(),
                              many=True).data,
            "attachments":
            AttachmentsSerializer(
                self.opportunity.opportunity_attachment.all(), many=True).data,
            "contacts":
            ContactSerializer(self.opportunity.contacts.all(), many=True).data,
            "users":
            ProfileSerializer(
                Profile.objects.filter(
                    is_active=True,
                    org=self.request.org).order_by("user__email"),
                many=True,
            ).data,
            "stage":
            STAGES,
            "lead_source":
            SOURCES,
            "currency":
            CURRENCY_CODES,
            "comment_permission":
            comment_permission,
            "users_mention":
            users_mention,
        })
        return Response(context)