Created current user billing address model in membership payment
This commit is contained in:
parent
082f39e9dc
commit
eaf1f1de86
1 changed files with 14 additions and 1 deletions
|
@ -366,6 +366,15 @@ class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView):
|
||||||
# Create Billing Address
|
# Create Billing Address
|
||||||
billing_address = form.save()
|
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
|
# Create membership plan
|
||||||
membership_data = {'type': membership_type}
|
membership_data = {'type': membership_type}
|
||||||
membership = Membership.create(membership_data)
|
membership = Membership.create(membership_data)
|
||||||
|
@ -454,12 +463,16 @@ class MembershipDeactivateView(LoginRequiredMixin, UpdateView):
|
||||||
class UserBillingAddressView(LoginRequiredMixin, UpdateView):
|
class UserBillingAddressView(LoginRequiredMixin, UpdateView):
|
||||||
model = UserBillingAddress
|
model = UserBillingAddress
|
||||||
form_class = UserBillingAddressForm
|
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')
|
success_url = reverse_lazy('digitalglarus:user_billing_address')
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
current_billing_address = self.request.user.billing_addresses.first()
|
current_billing_address = self.request.user.billing_addresses.first()
|
||||||
form_kwargs = super(UserBillingAddressView, self).get_form_kwargs()
|
form_kwargs = super(UserBillingAddressView, self).get_form_kwargs()
|
||||||
|
|
||||||
|
if not current_billing_address:
|
||||||
|
return form_kwargs
|
||||||
|
|
||||||
form_kwargs.update({
|
form_kwargs.update({
|
||||||
'initial': {
|
'initial': {
|
||||||
'street_address': current_billing_address.street_address,
|
'street_address': current_billing_address.street_address,
|
||||||
|
|
Loading…
Reference in a new issue