From 70f0fed63f05a7ddc1125965e5b5c14279eae9e4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Dec 2019 10:18:39 +0530 Subject: [PATCH 01/10] Add all_customers management command --- .../management/commands/all_customers.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 datacenterlight/management/commands/all_customers.py diff --git a/datacenterlight/management/commands/all_customers.py b/datacenterlight/management/commands/all_customers.py new file mode 100644 index 00000000..d529d28f --- /dev/null +++ b/datacenterlight/management/commands/all_customers.py @@ -0,0 +1,36 @@ +import json +import logging +import sys + +from django.core.management.base import BaseCommand +from membership.models import CustomUser +from hosting.models import ( + HostingOrder, VMDetail, UserCardDetail, UserHostingKey +) +logger = logging.getLogger(__name__) + + +class Command(BaseCommand): + help = '''Dumps the email addresses of all customers who have a VM''' + + def add_arguments(self, parser): + parser.add_argument('-a', '--all_registered', action='store_true', + help='All registered users') + + def handle(self, *args, **options): + all_registered = options['all_registered'] + all_customers_set = set() + if all_registered: + all_customers = CustomUser.objects.filter( + is_admin=False, validated=True + ) + for customer in all_customers: + all_customers_set.add(customer.email) + print(customer.email) + else: + all_hosting_orders = HostingOrder.objects.all() + for order in all_hosting_orders: + all_customers_set.add(order.customer.user.email) + print(order.customer.user.email) + + print("Total customers = %s" % len(all_customers_set)) From 991908c37ed51ff60beffe4f490e526ed5c8604d Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Dec 2019 10:52:20 +0530 Subject: [PATCH 02/10] Fix obtianing active customers only --- datacenterlight/management/commands/all_customers.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/datacenterlight/management/commands/all_customers.py b/datacenterlight/management/commands/all_customers.py index d529d28f..2a2d6573 100644 --- a/datacenterlight/management/commands/all_customers.py +++ b/datacenterlight/management/commands/all_customers.py @@ -26,11 +26,13 @@ class Command(BaseCommand): ) for customer in all_customers: all_customers_set.add(customer.email) - print(customer.email) else: - all_hosting_orders = HostingOrder.objects.all() + all_hosting_orders = HostingOrder.objects.filter() + running_vm_details = VMDetail.objects.filter(terminated_at=None) + running_vm_ids = [rvm.vm_id for rvm in running_vm_details] for order in all_hosting_orders: - all_customers_set.add(order.customer.user.email) - print(order.customer.user.email) - + if order.vm_id in running_vm_ids: + all_customers_set.add(order.customer.user.email) + for cu in all_customers_set: + print(cu) print("Total customers = %s" % len(all_customers_set)) From 7442cbd9ca5c629a2724fc9c58356df400499f61 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Dec 2019 10:56:14 +0530 Subject: [PATCH 03/10] Print appropriate message --- datacenterlight/management/commands/all_customers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datacenterlight/management/commands/all_customers.py b/datacenterlight/management/commands/all_customers.py index 2a2d6573..93b89373 100644 --- a/datacenterlight/management/commands/all_customers.py +++ b/datacenterlight/management/commands/all_customers.py @@ -35,4 +35,7 @@ class Command(BaseCommand): all_customers_set.add(order.customer.user.email) for cu in all_customers_set: print(cu) - print("Total customers = %s" % len(all_customers_set)) + if all_registered: + print("All registered users = %s" % len(all_customers_set)) + else: + print("Total active customers = %s" % len(all_customers_set)) From 6666e40ec4430d8bd50d8dce632b5024bbca715a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Dec 2019 11:00:37 +0530 Subject: [PATCH 04/10] Remove unused imports --- datacenterlight/management/commands/all_customers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datacenterlight/management/commands/all_customers.py b/datacenterlight/management/commands/all_customers.py index 93b89373..adbd8552 100644 --- a/datacenterlight/management/commands/all_customers.py +++ b/datacenterlight/management/commands/all_customers.py @@ -1,12 +1,12 @@ -import json import logging -import sys from django.core.management.base import BaseCommand -from membership.models import CustomUser + from hosting.models import ( - HostingOrder, VMDetail, UserCardDetail, UserHostingKey + HostingOrder, VMDetail ) +from membership.models import CustomUser + logger = logging.getLogger(__name__) From 859249b894dfa15892ada26b3146df9941fdbca1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Dec 2019 11:20:47 +0530 Subject: [PATCH 05/10] Update Changelog --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 17efb793..c2aed106 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2.7.1: 2019-12-14 + * feature: Add management command to list active VM customers (MR!723) 2.7: 2019-12-9 * feature: EU VAT for new subscriptions (MR!721) Notes for deployment: From 922fea3bf4536c27e74668d22228a595a92ef6af Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Dec 2019 18:41:47 +0530 Subject: [PATCH 06/10] Add vat rates for AD, TK, IS --- vat_rates.csv | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vat_rates.csv b/vat_rates.csv index 4a3ec440..74422f48 100644 --- a/vat_rates.csv +++ b/vat_rates.csv @@ -316,3 +316,6 @@ IM",GBP,0.1,standard, 2019-11-15,,FR,EUR,0.2,standard,France standard VAT (added manually) 2019-11-15,,GR,EUR,0.24,standard,Greece standard VAT (added manually) 2019-11-15,,GB,EUR,0.2,standard,UK standard VAT (added manually) +2019-12-17,,AD,EUR,0.045,standard,Andorra standard VAT (added manually) +2019-12-17,,TK,EUR,0.18,standard,Turkey standard VAT (added manually) +2019-12-17,,IS,EUR,0.24,standard,Iceland standard VAT (added manually) From 69061c016b6c42921946036ccdc0176214f76de4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Dec 2019 18:45:29 +0530 Subject: [PATCH 07/10] Improve string representation of the billing address --- utils/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/models.py b/utils/models.py index c969a60c..8cd529e0 100644 --- a/utils/models.py +++ b/utils/models.py @@ -20,7 +20,10 @@ class BaseBillingAddress(models.Model): class BillingAddress(BaseBillingAddress): def __str__(self): - return self.street_address + return "%s, %s, %s, %s, %s" % ( + self.cardholder_name, self.street_address, self.city, + self.postal_code, self.country + ) class UserBillingAddress(BaseBillingAddress): @@ -28,7 +31,10 @@ class UserBillingAddress(BaseBillingAddress): current = models.BooleanField(default=True) def __str__(self): - return self.street_address + return "%s, %s, %s, %s, %s" % ( + self.cardholder_name, self.street_address, self.city, + self.postal_code, self.country + ) def to_dict(self): return { From c4013178f521f2e14b1a45429afae5c2283bc4a6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Dec 2019 18:45:39 +0530 Subject: [PATCH 08/10] Update Changelog --- Changelog | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Changelog b/Changelog index c2aed106..09b362fe 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,11 @@ +2.7.2: 2019-12-17 + * Add vat rates for AD, TK and IS + * Improve billing address' string representation + Notes for deployment: + - Import the newly added vat rates into db + ``` + ./manage.py import_vat_rates vat_rates.csv + ``` 2.7.1: 2019-12-14 * feature: Add management command to list active VM customers (MR!723) 2.7: 2019-12-9 From ed74504270662d58476dcc880b83cc374925314f Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 18 Dec 2019 19:33:44 +0530 Subject: [PATCH 09/10] Bugfix: Swiss VAT wrongly being applied to non EU customers --- datacenterlight/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 8ed0b794..952fa47f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -619,6 +619,7 @@ class OrderConfirmationView(DetailView, FormView): vm_specs["vat_country"] = user_vat_country vm_specs["discount"] = discount vm_specs["total_price"] = round(price + vat - discount['amount'], 2) + request.session['specs'] = vm_specs context.update({ 'vm': vm_specs, From a8cc07d95fd7a9227f871059d03a9df4af6be2b8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 18 Dec 2019 19:36:22 +0530 Subject: [PATCH 10/10] Update Changelog for 2.7.3 --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 09b362fe..7f68ac8b 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2.7.3: 2019-12-18 + * Bugfix: Swiss VAT being wrongly added to non-EU customers 2.7.2: 2019-12-17 * Add vat rates for AD, TK and IS * Improve billing address' string representation