예제 #1
0
 def post(self, request, *args, **kwargs):
     self.object = None
     form = self.get_form()
     billing_form = BillingAddressForm(request.POST)
     shipping_form = ShippingAddressForm(request.POST, prefix='ship')
     if form.is_valid() and billing_form.is_valid() and shipping_form.is_valid():
         return self.form_valid(form, billing_form, shipping_form)
     else:
         return self.form_invalid(form, billing_form, shipping_form)
예제 #2
0
def add_account(request):
    users = User.objects.filter(is_active=True).order_by('email')
    account_form = AccountForm(assigned_to=users)
    billing_form = BillingAddressForm()
    shipping_form = ShippingAddressForm(prefix='ship')
    teams = Team.objects.all()
    assignedto_list = request.POST.getlist('assigned_to')
    teams_list = request.POST.getlist('teams')
    if request.method == 'POST':
        account_form = AccountForm(request.POST, assigned_to=users)
        billing_form = BillingAddressForm(request.POST)
        shipping_form = ShippingAddressForm(request.POST, prefix='ship')
        if account_form.is_valid() and billing_form.is_valid(
        ) and shipping_form.is_valid():
            billing_object = billing_form.save()
            shipping_object = shipping_form.save()
            account_object = account_form.save(commit=False)
            account_object.billing_address = billing_object
            account_object.shipping_address = shipping_object
            account_object.created_by = request.user
            account_object.save()
            account_object.assigned_to.add(*assignedto_list)
            account_object.teams.add(*teams_list)
            if request.POST.get("savenewform"):
                return redirect("accounts:new_account")
            else:
                return redirect("accounts:list")
        else:
            return render(
                request, 'accounts/create_account.html', {
                    'account_form': account_form,
                    'billing_form': billing_form,
                    'shipping_form': shipping_form,
                    'industries': INDCHOICES,
                    'countries': COUNTRIES,
                    'users': users,
                    'teams': teams,
                    'assignedto_list': assignedto_list,
                    'teams_list': teams_list
                })

    else:
        return render(
            request, 'accounts/create_account.html', {
                'account_form': account_form,
                'billing_form': billing_form,
                'shipping_form': shipping_form,
                'industries': INDCHOICES,
                'countries': COUNTRIES,
                'users': users,
                'teams': teams,
                'assignedto_list': assignedto_list,
                'teams_list': teams_list
            })
예제 #3
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form = self.get_form()
        billing_form = BillingAddressForm(request.POST,
                                          instance=self.object.billing_address)
        shipping_form = ShippingAddressForm(
            request.POST, instance=self.object.shipping_address, prefix='ship')
        if form.is_valid() and billing_form.is_valid(
        ) and shipping_form.is_valid():
            return self.form_valid(form, billing_form, shipping_form)

        return self.form_invalid(form, billing_form, shipping_form)
예제 #4
0
파일: views.py 프로젝트: silpol/Django-CRM
def edit_account(request, edid):
    account_instance = get_object_or_404(Account, id=edid)
    account_billing_address = account_instance.billing_address
    account_shipping_address = account_instance.shipping_address
    users = User.objects.filter(is_active=True).order_by('email')
    account_form = AccountForm(instance=account_instance, assigned_to=users)
    billing_form = BillingAddressForm(instance=account_billing_address)
    shipping_form = ShippingAddressForm(prefix='ship',
                                        instance=account_shipping_address)
    teams = Team.objects.all()
    assignedto_list = request.POST.getlist('assigned_to')
    teams_list = request.POST.getlist('teams')
    if request.method == 'POST':
        account_form = AccountForm(request.POST,
                                   instance=account_instance,
                                   assigned_to=users)
        billing_form = BillingAddressForm(request.POST,
                                          instance=account_billing_address)
        shipping_form = ShippingAddressForm(request.POST,
                                            instance=account_shipping_address,
                                            prefix='ship')
        if account_form.is_valid() and billing_form.is_valid(
        ) and shipping_form.is_valid():
            billing_object = billing_form.save()
            shipping_object = shipping_form.save()
            account_object = account_form.save(commit=False)
            account_object.billing_address = billing_object
            account_object.shipping_address = shipping_object
            account_object.created_by = request.user
            account_object.save()
            account_object.assigned_to.clear()
            account_object.assigned_to.add(*assignedto_list)
            account_object.teams.clear()
            account_object.teams.add(*teams_list)
            return redirect("accounts:list")
        else:
            return render(
                request, 'create_account.html', {
                    'account_form':
                    account_form,
                    'billing_form':
                    billing_form,
                    'shipping_form':
                    shipping_form,
                    'account_obj':
                    account_instance,
                    'billing_obj':
                    account_billing_address,
                    'shipping_obj':
                    account_shipping_address,
                    'countries':
                    COUNTRIES,
                    'industries':
                    INDCHOICES,
                    'teams':
                    teams,
                    'users':
                    users,
                    'assignedto_list':
                    [int(user_id) for user_id in assignedto_list],
                    'teams_list':
                    teams_list
                })
    else:
        return render(
            request, 'create_account.html', {
                'account_form': account_form,
                'billing_form': billing_form,
                'shipping_form': shipping_form,
                'account_obj': account_instance,
                'billing_obj': account_billing_address,
                'shipping_obj': account_shipping_address,
                'countries': COUNTRIES,
                'industries': INDCHOICES,
                'teams': teams,
                'users': users,
                'assignedto_list': assignedto_list,
                'teams_list': teams_list
            })
예제 #5
0
def leads_convert(request, pk):
    account_form = AccountForm()
    billing_form = BillingAddressForm()
    shipping_form = ShippingAddressForm(prefix='ship')
    lead_objects = Lead.objects.all()
    lead_obj = Lead.objects.get(id=pk)
    accounts = Account.objects.all()
    contact_form = ContactForm()
    opportunity_form = OpportunityForm()
    teams = Team.objects.all()
    if request.method == "POST":
        if request.POST.get('accountname') == "on":
            account_form = AccountForm(request.POST)
            billing_form = BillingAddressForm(request.POST)
            shipping_form = ShippingAddressForm(request.POST, prefix='ship')
            if account_form.is_valid() and billing_form.is_valid(
            ) and shipping_form.is_valid():
                billing_object = billing_form.save()
                shipping_object = shipping_form.save()
                account_object = account_form.save(commit=False)
                account_object.billing_address = billing_object
                account_object.shipping_address = shipping_object
                account_object.created_by = request.user
                account_object.save()
                lead_obj.delete()
                return HttpResponseRedirect(reverse('leads:list'))
            else:
                street1 = request.POST.get('street')
                city1 = request.POST.get('city')
                state1 = request.POST.get('state')
                postcode1 = request.POST.get('postcode')
                country1 = request.POST.get('country')
                shipdata = {
                    'street1': street1,
                    'city1': city1,
                    'state1': state1,
                    'postcode1': postcode1,
                    'country1': country1
                }
                return render(
                    request, 'checkbox.html', {
                        'account_form': account_form,
                        'form1': billing_form,
                        'form2': shipping_form,
                        'form5': COUNTRIES,
                        'stages': STAGES,
                        'acc_error': account_form.errors,
                        'shipdata': shipdata,
                        'sources': LEAD_SOURCE,
                        'industries': INDCHOICES,
                        'teams': teams,
                        'task': lead_objects,
                        'post': lead_obj,
                        'accounts': accounts,
                        'counties': COUNTRIES
                    })

        if request.POST.get('contactname') == "on":
            contact_form = ContactForm(request.POST)
            address_form = BillingAddressForm(request.POST)
            if contact_form.is_valid() and address_form.is_valid():
                address_obj = address_form.save()
                contact_obj = contact_form.save(commit=False)
                contact_obj.address = address_obj
                contact_obj.created_by = request.user
                contact_obj.save()
                return HttpResponseRedirect(reverse('contacts:list'))
            else:
                return render(
                    request, 'checkbox.html', {
                        'post': lead_obj,
                        'accounts': accounts,
                        'teams': teams,
                        'contact_form': contact_form,
                        'address_form': address_form
                    })
        if request.POST.get('opportunityname') == "on":
            opportunity_form = OpportunityForm(request.POST)
            if opportunity_form.is_valid():
                opportunity_form.save()
                return HttpResponseRedirect(reverse('opportunities:list'))
            else:
                return render(
                    request, 'checkbox.html', {
                        'post': lead_obj,
                        'accounts': accounts,
                        'sources': LEAD_SOURCE,
                        'teams': teams,
                        'stages': STAGES,
                        'opportunity_form': opportunity_form
                    })
    else:
        return render(
            request, 'checkbox.html', {
                'form': account_form,
                'form1': billing_form,
                'form2': shipping_form,
                'form5': COUNTRIES,
                'industries': INDCHOICES,
                'teams': teams,
                'task': lead_objects,
                'counties': COUNTRIES,
                'post': lead_obj,
                'accounts': accounts
            })