From eaf1f1de86aac54cb6599234bddd75efb60c30d8 Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 13 Oct 2016 23:50:13 -0500 Subject: [PATCH] Created current user billing address model in membership payment --- digitalglarus/views.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index f2dfb4ab..473b68a7 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -366,6 +366,15 @@ class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView): # Create Billing Address billing_address = form.save() + # Create Billing Address for User if he does not have one + if not customer.user.billing_addresses.count(): + data.update({ + 'user': customer.user.id + }) + billing_address_user_form = UserBillingAddressForm(data) + billing_address_user_form.is_valid() + billing_address_user_form.save() + # Create membership plan membership_data = {'type': membership_type} membership = Membership.create(membership_data) @@ -454,12 +463,16 @@ class MembershipDeactivateView(LoginRequiredMixin, UpdateView): class UserBillingAddressView(LoginRequiredMixin, UpdateView): model = UserBillingAddress form_class = UserBillingAddressForm - template_name = "digitalglarus/user_billing_address.html" + template_name = "digitalglarus/user_billing_address.html" success_url = reverse_lazy('digitalglarus:user_billing_address') def get_form_kwargs(self): current_billing_address = self.request.user.billing_addresses.first() form_kwargs = super(UserBillingAddressView, self).get_form_kwargs() + + if not current_billing_address: + return form_kwargs + form_kwargs.update({ 'initial': { 'street_address': current_billing_address.street_address,