Make VAT number a part of billing address

This commit is contained in:
PCoder 2019-12-21 08:43:34 +05:30
parent c9de757bc7
commit f566aa8a2e
8 changed files with 11 additions and 32 deletions

View File

@ -32,11 +32,10 @@
{{billing_address.cardholder_name}}<br> {{billing_address.cardholder_name}}<br>
{{billing_address.street_address}}, {{billing_address.postal_code}}<br> {{billing_address.street_address}}, {{billing_address.postal_code}}<br>
{{billing_address.city}}, {{billing_address.country}} {{billing_address.city}}, {{billing_address.country}}
{% if request.user.vat_number %} {% if billing_address.vat_number %}
<br/>{% trans "VAT Number" %} {{request.user.vat_number}} <br/>{% trans "VAT Number" %} {{billing_address.vat_number}}
{% endif %} {% endif %}
{% endwith %} {% endwith %}
</p> </p>
</address> </address>
</div> </div>
@ -211,4 +210,4 @@
{% trans "Some problem encountered. Please try again later." as err_msg %} {% trans "Some problem encountered. Please try again later." as err_msg %}
var create_vm_error_message = '{{err_msg|safe}}'; var create_vm_error_message = '{{err_msg|safe}}';
</script> </script>
{%endblock%} {%endblock%}

View File

@ -254,9 +254,6 @@ class PaymentOrderView(FormView):
billing_address_form = BillingAddressForm( billing_address_form = BillingAddressForm(
instance=self.request.user.billing_addresses.first() instance=self.request.user.billing_addresses.first()
) )
billing_address_form.fields['vat_number'].initial = (
self.request.user.vat_number
)
user = self.request.user user = self.request.user
if hasattr(user, 'stripecustomer'): if hasattr(user, 'stripecustomer'):
stripe_customer = user.stripecustomer stripe_customer = user.stripecustomer
@ -491,9 +488,6 @@ class PaymentOrderView(FormView):
customer = StripeCustomer.get_or_create( customer = StripeCustomer.get_or_create(
email=this_user.get('email'), token=token email=this_user.get('email'), token=token
) )
request.user.vat_number = address_form.cleaned_data.get(
"vat_number")
request.user.save()
else: else:
user_email = address_form.cleaned_data.get('email') user_email = address_form.cleaned_data.get('email')
user_name = address_form.cleaned_data.get('name') user_name = address_form.cleaned_data.get('name')
@ -949,11 +943,6 @@ class OrderConfirmationView(DetailView, FormView):
'user': custom_user.id '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: if 'generic_payment_type' in request.session:
stripe_cus = StripeCustomer.objects.filter( stripe_cus = StripeCustomer.objects.filter(
stripe_id=stripe_api_cus_id stripe_id=stripe_api_cus_id
@ -964,6 +953,7 @@ class OrderConfirmationView(DetailView, FormView):
city=billing_address_data['city'], city=billing_address_data['city'],
postal_code=billing_address_data['postal_code'], postal_code=billing_address_data['postal_code'],
country=billing_address_data['country'] country=billing_address_data['country']
vat_number=billing_address_data['vat_number']
) )
billing_address.save() billing_address.save()

View File

@ -70,8 +70,8 @@
{{invoice.order.billing_address.postal_code}}<br> {{invoice.order.billing_address.postal_code}}<br>
{{invoice.order.billing_address.city}}, {{invoice.order.billing_address.city}},
{{invoice.order.billing_address.country}} {{invoice.order.billing_address.country}}
{% if invoice.customer.user.vat_number %} {% if invoice.order.billing_address.vat_number %}
<br/>{% trans "VAT Number" %} {{invoice.customer.user.vat_number}} <br/>{% trans "VAT Number" %} {{invoice.order.billing_address.vat_number}}
{% endif %} {% endif %}
{% endif %} {% endif %}
</p> </p>

View File

@ -67,8 +67,8 @@
{{billing_address.cardholder_name}}<br> {{billing_address.cardholder_name}}<br>
{{billing_address.street_address}}, {{billing_address.postal_code}}<br> {{billing_address.street_address}}, {{billing_address.postal_code}}<br>
{{billing_address.city}}, {{billing_address.country}} {{billing_address.city}}, {{billing_address.country}}
{% if user.vat_number %} {% if billing_address.vat_number %}
<br/>{% trans "VAT Number" %} {{user.vat_number}} <br/>{% trans "VAT Number" %} {{billing_address.vat_number}}
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endif %} {% endif %}

View File

@ -549,12 +549,9 @@ class SettingsView(LoginRequiredMixin, FormView):
Check if the user already saved contact details. If so, then show Check if the user already saved contact details. If so, then show
the form populated with those details, to let user change them. the form populated with those details, to let user change them.
""" """
return form_class(
bill_form = form_class(
instance=self.request.user.billing_addresses.first(), instance=self.request.user.billing_addresses.first(),
**self.get_form_kwargs()) **self.get_form_kwargs())
bill_form.fields['vat_number'].initial = self.request.user.vat_number
return bill_form
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(SettingsView, self).get_context_data(**kwargs) context = super(SettingsView, self).get_context_data(**kwargs)
@ -630,9 +627,6 @@ class SettingsView(LoginRequiredMixin, FormView):
instance=self.request.user.billing_addresses.first(), instance=self.request.user.billing_addresses.first(),
data=billing_address_data) data=billing_address_data)
billing_address_user_form.save() 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") msg = _("Billing address updated successfully")
messages.add_message(request, messages.SUCCESS, msg) messages.add_message(request, messages.SUCCESS, msg)
else: else:
@ -705,7 +699,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
'city': current_billing_address.city, 'city': current_billing_address.city,
'postal_code': current_billing_address.postal_code, 'postal_code': current_billing_address.postal_code,
'country': current_billing_address.country, 'country': current_billing_address.country,
'vat_number': self.request.user.vat_number 'vat_number': current_billing_address.vat_number
} }
}) })
return form_kwargs return form_kwargs
@ -790,8 +784,6 @@ class PaymentVMView(LoginRequiredMixin, FormView):
reverse('hosting:payment') + '#payment_error') reverse('hosting:payment') + '#payment_error')
request.session['token'] = token request.session['token'] = token
request.session['billing_address_data'] = billing_address_data 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( self.request.session['order_confirm_url'] = "{url}?{query_params}".format(
url=reverse('hosting:order-confirmation'), url=reverse('hosting:order-confirmation'),
query_params='page=payment') query_params='page=payment')

View File

@ -117,8 +117,6 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
name = models.CharField(max_length=50, validators=[validate_name]) name = models.CharField(max_length=50, validators=[validate_name])
email = models.EmailField(unique=True) email = models.EmailField(unique=True)
username = models.CharField(max_length=60, unique=True, null=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) validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
in_ldap = models.BooleanField(default=False) in_ldap = models.BooleanField(default=False)
# By default, we initialize the validation_slug with appropriate value # By default, we initialize the validation_slug with appropriate value

View File

@ -120,7 +120,6 @@ class EditCreditCardForm(forms.Form):
class BillingAddressForm(forms.ModelForm): class BillingAddressForm(forms.ModelForm):
token = forms.CharField(widget=forms.HiddenInput(), required=False) token = forms.CharField(widget=forms.HiddenInput(), required=False)
card = forms.CharField(widget=forms.HiddenInput(), required=False) card = forms.CharField(widget=forms.HiddenInput(), required=False)
vat_number = forms.CharField(max_length=100)
class Meta: class Meta:
model = BillingAddress model = BillingAddress

View File

@ -13,6 +13,7 @@ class BaseBillingAddress(models.Model):
city = models.CharField(max_length=50) city = models.CharField(max_length=50)
postal_code = models.CharField(max_length=50) postal_code = models.CharField(max_length=50)
country = CountryField() country = CountryField()
vat_number = models.CharField(max_length=100)
class Meta: class Meta:
abstract = True abstract = True