From f566aa8a2e3c91e88d43b1e343b15007b3817533 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 21 Dec 2019 08:43:34 +0530 Subject: [PATCH] Make VAT number a part of billing address --- .../templates/datacenterlight/order_detail.html | 7 +++---- datacenterlight/views.py | 12 +----------- hosting/templates/hosting/invoice_detail.html | 4 ++-- hosting/templates/hosting/order_detail.html | 4 ++-- hosting/views.py | 12 ++---------- membership/models.py | 2 -- utils/forms.py | 1 - utils/models.py | 1 + 8 files changed, 11 insertions(+), 32 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 87ff3bd3..b7e28e62 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -32,11 +32,10 @@ {{billing_address.cardholder_name}}
{{billing_address.street_address}}, {{billing_address.postal_code}}
{{billing_address.city}}, {{billing_address.country}} - {% if request.user.vat_number %} -
{% trans "VAT Number" %} {{request.user.vat_number}} + {% if billing_address.vat_number %} +
{% trans "VAT Number" %} {{billing_address.vat_number}} {% endif %} {% endwith %} -

@@ -211,4 +210,4 @@ {% trans "Some problem encountered. Please try again later." as err_msg %} var create_vm_error_message = '{{err_msg|safe}}'; -{%endblock%} \ No newline at end of file +{%endblock%} diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 301049aa..078f64ac 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -254,9 +254,6 @@ class PaymentOrderView(FormView): billing_address_form = BillingAddressForm( instance=self.request.user.billing_addresses.first() ) - billing_address_form.fields['vat_number'].initial = ( - self.request.user.vat_number - ) user = self.request.user if hasattr(user, 'stripecustomer'): stripe_customer = user.stripecustomer @@ -491,9 +488,6 @@ class PaymentOrderView(FormView): customer = StripeCustomer.get_or_create( email=this_user.get('email'), token=token ) - request.user.vat_number = address_form.cleaned_data.get( - "vat_number") - request.user.save() else: user_email = address_form.cleaned_data.get('email') user_name = address_form.cleaned_data.get('name') @@ -949,11 +943,6 @@ class OrderConfirmationView(DetailView, FormView): 'user': custom_user.id }) - # Customer is created, we save his VAT Number - custom_user.vat_number = request.session.get( - 'billing_address_data').get("vat_number") - custom_user.save() - if 'generic_payment_type' in request.session: stripe_cus = StripeCustomer.objects.filter( stripe_id=stripe_api_cus_id @@ -964,6 +953,7 @@ class OrderConfirmationView(DetailView, FormView): city=billing_address_data['city'], postal_code=billing_address_data['postal_code'], country=billing_address_data['country'] + vat_number=billing_address_data['vat_number'] ) billing_address.save() diff --git a/hosting/templates/hosting/invoice_detail.html b/hosting/templates/hosting/invoice_detail.html index 3463e505..e5714b82 100644 --- a/hosting/templates/hosting/invoice_detail.html +++ b/hosting/templates/hosting/invoice_detail.html @@ -70,8 +70,8 @@ {{invoice.order.billing_address.postal_code}}
{{invoice.order.billing_address.city}}, {{invoice.order.billing_address.country}} - {% if invoice.customer.user.vat_number %} -
{% trans "VAT Number" %} {{invoice.customer.user.vat_number}} + {% if invoice.order.billing_address.vat_number %} +
{% trans "VAT Number" %} {{invoice.order.billing_address.vat_number}} {% endif %} {% endif %}

diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index 0ce72fa3..2ad17276 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -67,8 +67,8 @@ {{billing_address.cardholder_name}}
{{billing_address.street_address}}, {{billing_address.postal_code}}
{{billing_address.city}}, {{billing_address.country}} - {% if user.vat_number %} -
{% trans "VAT Number" %} {{user.vat_number}} + {% if billing_address.vat_number %} +
{% trans "VAT Number" %} {{billing_address.vat_number}} {% endif %} {% endwith %} {% endif %} diff --git a/hosting/views.py b/hosting/views.py index 39b43ad8..3f89496b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -549,12 +549,9 @@ class SettingsView(LoginRequiredMixin, FormView): Check if the user already saved contact details. If so, then show the form populated with those details, to let user change them. """ - - bill_form = form_class( + return form_class( instance=self.request.user.billing_addresses.first(), **self.get_form_kwargs()) - bill_form.fields['vat_number'].initial = self.request.user.vat_number - return bill_form def get_context_data(self, **kwargs): context = super(SettingsView, self).get_context_data(**kwargs) @@ -630,9 +627,6 @@ class SettingsView(LoginRequiredMixin, FormView): instance=self.request.user.billing_addresses.first(), data=billing_address_data) billing_address_user_form.save() - self.request.user.vat_number = billing_address_data.get( - "vat_number") - self.request.user.save() msg = _("Billing address updated successfully") messages.add_message(request, messages.SUCCESS, msg) else: @@ -705,7 +699,7 @@ class PaymentVMView(LoginRequiredMixin, FormView): 'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code, 'country': current_billing_address.country, - 'vat_number': self.request.user.vat_number + 'vat_number': current_billing_address.vat_number } }) return form_kwargs @@ -790,8 +784,6 @@ class PaymentVMView(LoginRequiredMixin, FormView): reverse('hosting:payment') + '#payment_error') request.session['token'] = token request.session['billing_address_data'] = billing_address_data - owner.vat_number = billing_address_data.get("vat_number") - owner.save() self.request.session['order_confirm_url'] = "{url}?{query_params}".format( url=reverse('hosting:order-confirmation'), query_params='page=payment') diff --git a/membership/models.py b/membership/models.py index 34ef73cc..80aaf408 100644 --- a/membership/models.py +++ b/membership/models.py @@ -117,8 +117,6 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): name = models.CharField(max_length=50, validators=[validate_name]) email = models.EmailField(unique=True) username = models.CharField(max_length=60, unique=True, null=True) - vat_number = models.CharField(max_length=100, default="") - validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) in_ldap = models.BooleanField(default=False) # By default, we initialize the validation_slug with appropriate value diff --git a/utils/forms.py b/utils/forms.py index 9855e367..71a675bc 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -120,7 +120,6 @@ class EditCreditCardForm(forms.Form): class BillingAddressForm(forms.ModelForm): token = forms.CharField(widget=forms.HiddenInput(), required=False) card = forms.CharField(widget=forms.HiddenInput(), required=False) - vat_number = forms.CharField(max_length=100) class Meta: model = BillingAddress diff --git a/utils/models.py b/utils/models.py index 8cd529e0..e70dea5c 100644 --- a/utils/models.py +++ b/utils/models.py @@ -13,6 +13,7 @@ class BaseBillingAddress(models.Model): city = models.CharField(max_length=50) postal_code = models.CharField(max_length=50) country = CountryField() + vat_number = models.CharField(max_length=100) class Meta: abstract = True