Skip to content

Commit

Permalink
new release (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
KingCSharp committed Oct 6, 2021
1 parent 984eb69 commit 67834d6
Show file tree
Hide file tree
Showing 95 changed files with 3,201 additions and 1,262 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*~
*.pyc
*~
*.swo
*.swp
db.sqlite3
Expand All @@ -23,3 +23,5 @@ local_settings.py
media
.sass-cache
server.log
.vscode
static
30 changes: 30 additions & 0 deletions accounts/migrations/0013_auto_20210913_1918.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2 on 2021-09-13 13:48

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('common', '0034_auto_20210913_1918'),
('accounts', '0012_remove_account_company'),
]

operations = [
migrations.AddField(
model_name='account',
name='company',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.company'),
),
migrations.AlterField(
model_name='account',
name='assigned_to',
field=models.ManyToManyField(related_name='account_assigned_users', to='common.Profile'),
),
migrations.AlterField(
model_name='account',
name='created_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='account_created_by', to='common.profile'),
),
]
18 changes: 18 additions & 0 deletions accounts/migrations/0014_rename_company_account_org.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-09-22 12:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('accounts', '0013_auto_20210913_1918'),
]

operations = [
migrations.RenameField(
model_name='account',
old_name='company',
new_name='org',
),
]
20 changes: 20 additions & 0 deletions accounts/migrations/0015_alter_account_org.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.7 on 2021-10-06 07:21

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('common', '0037_alter_profile_org'),
('accounts', '0014_rename_company_account_org'),
]

operations = [
migrations.AlterField(
model_name='account',
name='org',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='account_org', to='common.org'),
),
]
15 changes: 9 additions & 6 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _

from common.models import User
from common.models import Org, Profile
from common.utils import INDCHOICES, COUNTRIES
from phonenumber_field.modelfields import PhoneNumberField
from django.utils.text import slugify
Expand Down Expand Up @@ -50,7 +50,7 @@ class Account(models.Model):
website = models.URLField(_("Website"), blank=True, null=True)
description = models.TextField(blank=True, null=True)
created_by = models.ForeignKey(
User, related_name="account_created_by", on_delete=models.SET_NULL, null=True
Profile, related_name="account_created_by", on_delete=models.SET_NULL, null=True
)
created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
is_active = models.BooleanField(default=False)
Expand All @@ -67,8 +67,11 @@ class Account(models.Model):
contacts = models.ManyToManyField(
"contacts.Contact", related_name="account_contacts"
)
assigned_to = models.ManyToManyField(User, related_name="account_assigned_users")
assigned_to = models.ManyToManyField(Profile, related_name="account_assigned_users")
teams = models.ManyToManyField(Teams, related_name="account_teams")
org = models.ForeignKey(
Org, on_delete=models.SET_NULL, null=True, blank=True, related_name="account_org"
)

class Meta:
ordering = ["-created_on"]
Expand Down Expand Up @@ -102,21 +105,21 @@ def contact_values(self):
@property
def get_team_users(self):
team_user_ids = list(self.teams.values_list("users__id", flat=True))
return User.objects.filter(id__in=team_user_ids)
return Profile.objects.filter(id__in=team_user_ids)

@property
def get_team_and_assigned_users(self):
team_user_ids = list(self.teams.values_list("users__id", flat=True))
assigned_user_ids = list(self.assigned_to.values_list("id", flat=True))
user_ids = team_user_ids + assigned_user_ids
return User.objects.filter(id__in=user_ids)
return Profile.objects.filter(id__in=user_ids)

@property
def get_assigned_users_not_in_teams(self):
team_user_ids = list(self.teams.values_list("users__id", flat=True))
assigned_user_ids = list(self.assigned_to.values_list("id", flat=True))
user_ids = set(assigned_user_ids) - set(team_user_ids)
return User.objects.filter(id__in=list(user_ids))
return Profile.objects.filter(id__in=list(user_ids))


class Email(models.Model):
Expand Down
13 changes: 8 additions & 5 deletions accounts/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers
from accounts.models import Account, Email, Tags
from common.serializer import UserSerializer, AttachmentsSerializer
from common.serializer import ProfileSerializer, AttachmentsSerializer, OrganizationSerializer
from leads.serializer import LeadSerializer
from teams.serializer import TeamsSerializer
from contacts.serializer import ContactSerializer
Expand All @@ -13,10 +13,11 @@ class Meta:


class AccountSerializer(serializers.ModelSerializer):
created_by = UserSerializer()
created_by = ProfileSerializer()
lead = LeadSerializer()
org = OrganizationSerializer()
tags = TagsSerailizer(read_only=True, many=True)
assigned_to = UserSerializer(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)
Expand Down Expand Up @@ -49,6 +50,7 @@ class Meta:
"contacts",
"assigned_to",
"teams",
"org"
)


Expand Down Expand Up @@ -113,17 +115,18 @@ def __init__(self, *args, **kwargs):
if self.instance:
self.fields["lead"].required = False
self.fields["lead"].required = False
self.org = request_obj.org

def validate_name(self, name):
if self.instance:
if self.instance.name != name:
if not Account.objects.filter(name__iexact=name).exists():
if not Account.objects.filter(name__iexact=name, org=self.org).exists():
return name
raise serializers.ValidationError(
"Account already exists with this name"
)
return name
if not Account.objects.filter(name__iexact=name).exists():
if not Account.objects.filter(name__iexact=name, org=self.org).exists():
return name
raise serializers.ValidationError("Account already exists with this name")

Expand Down
14 changes: 14 additions & 0 deletions accounts/swagger_params.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from drf_yasg import openapi

organization_params_in_header = openapi.Parameter(
'org', openapi.IN_HEADER, required=True, type=openapi.TYPE_INTEGER)

organization_params = [
organization_params_in_header,
]

account_get_params = [
organization_params_in_header,
openapi.Parameter("name", openapi.IN_QUERY, type=openapi.TYPE_STRING),
openapi.Parameter("city", openapi.IN_QUERY, type=openapi.TYPE_STRING),
openapi.Parameter("tags", openapi.IN_QUERY, type=openapi.TYPE_STRING),
]

account_post_params = [
organization_params_in_header,
openapi.Parameter(
"name", openapi.IN_QUERY, required=True, type=openapi.TYPE_STRING
),
Expand Down Expand Up @@ -57,6 +66,7 @@
]

account_detail_get_params = [
organization_params_in_header,
openapi.Parameter(
"account_attachment",
openapi.IN_QUERY,
Expand All @@ -66,10 +76,12 @@
]

account_comment_edit_params = [
organization_params_in_header,
openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING),
]

account_detail_get_params = [
organization_params_in_header,
openapi.Parameter(
"account_attachment",
openapi.IN_QUERY,
Expand All @@ -79,10 +91,12 @@
]

account_comment_edit_params = [
organization_params_in_header,
openapi.Parameter("comment", openapi.IN_QUERY, type=openapi.TYPE_STRING),
]

account_mail_params = [
organization_params_in_header,
openapi.Parameter("from_email", openapi.IN_QUERY, type=openapi.TYPE_STRING),
openapi.Parameter("recipients", openapi.IN_QUERY, type=openapi.TYPE_STRING),
openapi.Parameter("message_subject", openapi.IN_QUERY, type=openapi.TYPE_STRING),
Expand Down
16 changes: 8 additions & 8 deletions accounts/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.template.loader import render_to_string

from accounts.models import Account, Email, EmailLog
from common.models import User
from common.models import User, Profile
from common.utils import convert_to_custom_timezone

app = Celery("redis://")
Expand All @@ -27,7 +27,7 @@ def send_email(email_obj_id):
).exists():
html = email_obj.message_body
context_data = {
"email": contact_obj.email if contact_obj.email else "",
"email": contact_obj.primary_email if contact_obj.primary_email else "",
"name": contact_obj.first_name
if contact_obj.first_name
else "" + " " + contact_obj.last_name
Expand All @@ -42,7 +42,7 @@ def send_email(email_obj_id):
html_content,
from_email=from_email,
to=[
contact_obj.email,
contact_obj.primary_email,
],
)
msg.content_subtype = "html"
Expand All @@ -65,14 +65,14 @@ def send_email_to_assigned_user(
account = Account.objects.filter(id=from_email).first()
created_by = account.created_by

for user in recipients:
for profile_id in recipients:
recipients_list = []
user = User.objects.filter(id=user, is_active=True).first()
if user:
recipients_list.append(user.email)
profile = Profile.objects.filter(id=profile_id, is_active=True).first()
if profile:
recipients_list.append(profile.user.email)
context = {}
context["url"] = protocol + "://" + domain
context["user"] = user
context["user"] = profile.user
context["account"] = account
context["created_by"] = created_by
subject = "Assigned a account for you."
Expand Down
2 changes: 1 addition & 1 deletion accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
urlpatterns = [
path("", views.AccountsListView.as_view()),
path("<int:pk>/", views.AccountDetailView.as_view()),
path("<int:pk>/create_mail", views.AccountCreateMailView.as_view()),
path("<int:pk>/create_mail/", views.AccountCreateMailView.as_view()),
path("comment/<int:pk>/", views.AccountCommentView.as_view()),
path("attachment/<int:pk>/", views.AccountAttachmentView.as_view()),
]
Loading

0 comments on commit 67834d6

Please sign in to comment.