From 92e525467968bbf7f9d7156f5ca6c541d89a0565 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2023 12:14:48 +0530 Subject: [PATCH] Fix customer name and vat rate --- .../management/commands/change_ch_vatrate_2023.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hosting/management/commands/change_ch_vatrate_2023.py b/hosting/management/commands/change_ch_vatrate_2023.py index 43cb1d92..cbf77060 100644 --- a/hosting/management/commands/change_ch_vatrate_2023.py +++ b/hosting/management/commands/change_ch_vatrate_2023.py @@ -6,6 +6,7 @@ import stripe from hosting.models import VATRates from utils.hosting_utils import get_vat_rate_for_country from django.conf import settings +from membership.models import CustomUser, StripeCustomer stripe.api_key = settings.STRIPE_API_PRIVATE_KEY @@ -81,15 +82,17 @@ class Command(BaseCommand): writer = csv.DictWriter(csv_file, fieldnames=csv_headers) writer.writeheader() - for subscription in subscriptions: + for subscription in ch_subs: subscription_id = subscription["id"] - customer_name = subscription.get("customer", "") + stripe_customer_id = subscription.get("customer", "") + vat_rate = subscription.get("tax_percent", "") + c_user = CustomUser.objects.get( + id=StripeCustomer.objects.filter(stripe_id=stripe_customer_id)[0].id) + customer_name = "%s - %s - %s" % (c_user.name, c_user.email, stripe_customer_id) items = subscription.get("items", {}).get("data", []) - for item in items: subscription_name = item.get("plan", {}).get("id", "") amount = item.get("plan", {}).get("amount", "") - vat_rates = item.get("tax_rates", []) # Convert amount to a proper format (e.g., cents to dollars) amount_in_chf = amount / 100 # Adjust this conversion as needed @@ -100,7 +103,7 @@ class Command(BaseCommand): "subscription_id": subscription_id, "subscription_name": subscription_name, "amount": amount_in_chf, - "vat_rate": ", ".join(vat_rates) # Fill in VAT rate if available + "vat_rate": vat_rate # Fill in VAT rate if available })