diff --git a/accounts/forms.py b/accounts/forms.py index 2815fbf9..1e16342b 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -4,9 +4,12 @@ from common.models import Comment, Attachments, User from leads.models import Lead from contacts.models import Contact from django.db.models import Q +from teams.models import Teams class AccountForm(forms.ModelForm): + teams_queryset = [] + teams = forms.MultipleChoiceField(choices=teams_queryset) def __init__(self, *args, **kwargs): account_view = kwargs.pop('account', False) @@ -39,13 +42,17 @@ class AccountForm(forms.ModelForm): # self.fields["lead"].queryset = Lead.objects.all( # ).exclude(status='closed') if request_user.role == 'ADMIN': - self.fields["lead"].queryset = Lead.objects.filter().exclude(status='closed') + self.fields["lead"].queryset = Lead.objects.filter().exclude( + status='closed') self.fields["contacts"].queryset = Contact.objects.filter() + self.fields["teams"].choices = [(team.get('id'), team.get('name')) for team in Teams.objects.all().values('id', 'name')] + self.fields["teams"].required = False else: self.fields["lead"].queryset = Lead.objects.filter( Q(assigned_to__in=[request_user]) | Q(created_by=request_user)).exclude(status='closed') self.fields["contacts"].queryset = Contact.objects.filter( Q(assigned_to__in=[request_user]) | Q(created_by=request_user)) + self.fields["teams"].required = False self.fields['assigned_to'].required = False if account_view: @@ -56,6 +63,10 @@ class AccountForm(forms.ModelForm): self.fields['billing_postcode'].required = True self.fields['billing_country'].required = True + # lead is not mandatory while editing + if self.instance.id: + self.fields['lead'].required = False + class Meta: model = Account fields = ('name', 'phone', 'email', 'website', 'industry', diff --git a/accounts/templates/create_account.html b/accounts/templates/create_account.html index ef087b88..c7c587ea 100644 --- a/accounts/templates/create_account.html +++ b/accounts/templates/create_account.html @@ -67,7 +67,7 @@ --------- {% for lead in leads %} - {{lead.first_name}} {{lead.last_name}} + {{lead.first_name}} {{lead.last_name}} {% endfor %} {{ account_form.lead.errors }} @@ -142,11 +142,20 @@
The following tags can be used on both Plain text or HTML. Add these tags to customize the email template, these tags will be replaced with the associated contact details while the mails are sent.
{% templatetag openvariable %} first_name {% templatetag closevariable %}
{% templatetag openvariable %} last_name {% templatetag closevariable %}
{% templatetag openvariable %} name {% templatetag closevariable %}
{% templatetag openvariable %} email {% templatetag closevariable %}
{% templatetag openvariable %} company_name {% templatetag closevariable %}
{% templatetag openvariable %} city {% templatetag closevariable %}
{% templatetag openvariable %} state {% templatetag closevariable %}