Compare commits
No commits in common. "master" and "make-docker-build-succesful" have entirely different histories.
master
...
make-docke
10 changed files with 10 additions and 258 deletions
|
@ -27,6 +27,3 @@ COPY requirements.txt ./
|
|||
RUN LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install --no-cache-dir -r requirements.txt"
|
||||
|
||||
COPY ./ .
|
||||
COPY entrypoint.sh /
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh" ]
|
||||
|
|
|
@ -15,9 +15,4 @@ tag=${tagprefix}:${version}
|
|||
set -ex
|
||||
|
||||
docker build -t "${tag}" .
|
||||
|
||||
push=$1; shift
|
||||
|
||||
if [ "$push" ]; then
|
||||
docker push "${tag}"
|
||||
fi
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from datacenterlight.tasks import handle_metadata_and_emails
|
||||
from datacenterlight.models import StripePlan
|
||||
from opennebula_api.models import OpenNebulaManager
|
||||
from membership.models import CustomUser
|
||||
from hosting.models import GenericProduct
|
||||
import logging
|
||||
import json
|
||||
import sys
|
||||
import stripe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '''Stripe plans created before version 3.4 saved the plan name like generic-{subscription_id}-amount. This
|
||||
command aims at replacing this with the actual product name
|
||||
'''
|
||||
|
||||
def handle(self, *args, **options):
|
||||
cnt = 0
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
'In Fix generic stripe plan product names'
|
||||
)
|
||||
)
|
||||
plans_to_change = StripePlan.objects.filter(stripe_plan_id__startswith='generic')
|
||||
for plan in plans_to_change:
|
||||
response = input("Press 'y' to continue: ")
|
||||
|
||||
# Check if the user entered 'y'
|
||||
if response.lower() == 'y':
|
||||
plan_name = plan.stripe_plan_id
|
||||
first_index_hyphen = plan_name.index("-") + 1
|
||||
product_id = plan_name[
|
||||
first_index_hyphen:(plan_name[first_index_hyphen:].index("-")) + first_index_hyphen]
|
||||
gp = GenericProduct.objects.get(id=product_id)
|
||||
if gp:
|
||||
cnt += 1
|
||||
# update stripe
|
||||
sp = stripe.Plan.retrieve(plan_name)
|
||||
pr = stripe.Product.retrieve(sp.product)
|
||||
pr.name = gp.product_name
|
||||
pr.save()
|
||||
# update local
|
||||
spl = StripePlan.objects.get(stripe_plan_id=plan_name)
|
||||
spl.stripe_plan_name = gp.product_name
|
||||
spl.save()
|
||||
print("%s. %s => %s" % (cnt, plan_name, gp.product_name))
|
||||
else:
|
||||
print("Invalid input. Please try again.")
|
||||
sys.exit()
|
||||
|
||||
print("Done")
|
|
@ -73,7 +73,6 @@ def get_line_item_from_hosting_order_charge(hosting_order_id):
|
|||
:return:
|
||||
"""
|
||||
try:
|
||||
print("Hositng order id = %s" % hosting_order_id)
|
||||
hosting_order = HostingOrder.objects.get(id = hosting_order_id)
|
||||
if hosting_order.stripe_charge_id:
|
||||
return mark_safe("""
|
||||
|
@ -145,7 +144,7 @@ def get_line_item_from_stripe_invoice(invoice):
|
|||
""".format(
|
||||
vm_id=vm_id if vm_id > 0 else "",
|
||||
ip_addresses=mark_safe(get_ip_addresses(vm_id)) if vm_id > 0 else
|
||||
mark_safe(get_product_name(plan_name)) if plan_name.startswith("generic-") else plan_name,
|
||||
mark_safe(get_product_name(plan_name)),
|
||||
period=mark_safe("%s — %s" % (
|
||||
datetime.datetime.fromtimestamp(start_date).strftime('%Y-%m-%d'),
|
||||
datetime.datetime.fromtimestamp(end_date).strftime('%Y-%m-%d'))),
|
||||
|
@ -161,7 +160,8 @@ def get_product_name(plan_name):
|
|||
product_name = ""
|
||||
if plan_name and plan_name.startswith("generic-"):
|
||||
first_index_hyphen = plan_name.index("-") + 1
|
||||
product_id = plan_name[first_index_hyphen:(plan_name[first_index_hyphen:].index("-")) + first_index_hyphen]
|
||||
product_id = plan_name[first_index_hyphen:
|
||||
(plan_name[first_index_hyphen:].index("-")) + first_index_hyphen]
|
||||
try:
|
||||
product = GenericProduct.objects.get(id=product_id)
|
||||
product_name = product.product_name
|
||||
|
|
|
@ -42,8 +42,6 @@ from .utils import (
|
|||
get_cms_integration, create_vm, clear_all_session_vars, validate_vat_number
|
||||
)
|
||||
|
||||
from datacenterlight.templatetags.custom_tags import get_product_name
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -902,21 +900,15 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
2
|
||||
)
|
||||
)
|
||||
stripe_plan_id = "generic-{0}-{1:.2f}".format(
|
||||
plan_name = "generic-{0}-{1:.2f}".format(
|
||||
request.session['generic_payment_details']['product_id'],
|
||||
amount_to_be_charged
|
||||
)
|
||||
try:
|
||||
product = GenericProduct.objects.get(id=request.session['generic_payment_details']['product_id'])
|
||||
plan_name = product.product_name
|
||||
except Exception as ex:
|
||||
logger.debug("Errori {}" % str(ex))
|
||||
plan_name = get_product_name(stripe_plan_id)
|
||||
stripe_plan_id = plan_name
|
||||
recurring_interval = request.session['generic_payment_details']['recurring_interval']
|
||||
if recurring_interval == "year":
|
||||
stripe_plan_id = "{}-yearly".format(stripe_plan_id)
|
||||
plan_name = "{} (yearly)".format(plan_name)
|
||||
logger.debug("Plan name = {}, Stripe Plan id = {}".format(plan_name, stripe_plan_id))
|
||||
plan_name = "{}-yearly".format(plan_name)
|
||||
stripe_plan_id = plan_name
|
||||
else:
|
||||
template = request.session.get('template')
|
||||
specs = request.session.get('specs')
|
||||
|
@ -1009,8 +1001,6 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
# due to some reason. So, we would want to dissociate this card
|
||||
# here.
|
||||
# ...
|
||||
logger.debug("In 1 ***")
|
||||
logger.debug("stripe_subscription_obj == %s" % stripe_subscription_obj)
|
||||
msg = subscription_result.get('error')
|
||||
return show_error(msg, self.request)
|
||||
elif stripe_subscription_obj.status == 'incomplete':
|
||||
|
@ -1224,7 +1214,6 @@ def set_user_card(card_id, stripe_api_cus_id, custom_user,
|
|||
stripe_customer=custom_user.stripecustomer,
|
||||
card_details=card_details_response
|
||||
)
|
||||
logger.debug("ucd = %s" % ucd)
|
||||
UserCardDetail.save_default_card_local(
|
||||
custom_user.stripecustomer.stripe_id,
|
||||
ucd.card_id
|
||||
|
@ -1234,7 +1223,6 @@ def set_user_card(card_id, stripe_api_cus_id, custom_user,
|
|||
'brand': ucd.brand,
|
||||
'card_id': ucd.card_id
|
||||
}
|
||||
logger.debug("card_detail_dict = %s" % card_details_dict)
|
||||
return card_details_dict
|
||||
|
||||
|
||||
|
@ -1439,7 +1427,6 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
|
||||
card_details_dict = set_user_card(card_id, stripe_api_cus_id, custom_user,
|
||||
card_details_response)
|
||||
logger.debug("after set_user_card %s" % card_details_dict)
|
||||
|
||||
# Save billing address
|
||||
billing_address_data.update({
|
||||
|
@ -1462,7 +1449,6 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
vat_number=billing_address_data['vat_number']
|
||||
)
|
||||
billing_address.save()
|
||||
logger.debug("billing_address saved")
|
||||
|
||||
order = HostingOrder.create(
|
||||
price=request['generic_payment_details']['amount'],
|
||||
|
@ -1470,7 +1456,6 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
billing_address=billing_address,
|
||||
vm_pricing=VMPricing.get_default_pricing()
|
||||
)
|
||||
logger.debug("hosting order created")
|
||||
|
||||
# Create a Hosting Bill
|
||||
HostingBill.create(customer=stripe_cus,
|
||||
|
@ -1527,9 +1512,7 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
["%s=%s" % (k, v) for (k, v) in context.items()]),
|
||||
'reply_to': [context['email']],
|
||||
}
|
||||
logger.debug("Sending email")
|
||||
send_plain_email_task.delay(email_data)
|
||||
logger.debug("After Sending email")
|
||||
recurring_text = _(" This is a monthly recurring plan.")
|
||||
if gp_details['recurring_interval'] == "year":
|
||||
recurring_text = _(" This is an yearly recurring plan.")
|
||||
|
@ -1553,7 +1536,6 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
),
|
||||
'reply_to': ['info@ungleich.ch'],
|
||||
}
|
||||
logger.debug("Before Sending customer email")
|
||||
send_plain_email_task.delay(email_data)
|
||||
redirect_url = reverse('datacenterlight:index')
|
||||
logger.debug("Sent user/admin emails")
|
||||
|
|
|
@ -777,9 +777,3 @@ if DEBUG:
|
|||
from .local import * # flake8: noqa
|
||||
else:
|
||||
from .prod import * # flake8: noqa
|
||||
|
||||
# Try to load dynamic configuration, if it exists
|
||||
try:
|
||||
from .dynamic import * # flake8: noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -uex
|
||||
|
||||
cd /usr/src/app/
|
||||
cat > dynamicweb/settings/dynamic.py <<EOF
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': '${POSTGRES_DB}',
|
||||
'USER': '${POSTGRES_USER}',
|
||||
'PASSWORD': '${POSTGRES_PASSWORD}',
|
||||
'HOST': '${POSTGRES_HOST}',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
exec "$@"
|
|
@ -1,143 +0,0 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
import datetime
|
||||
import csv
|
||||
import logging
|
||||
import stripe
|
||||
from hosting.models import VATRates, StripeTaxRate
|
||||
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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '''FI vat rate changes on 2024-09-01 from 24% to 25.5%. This commands makes the necessary changes'''
|
||||
|
||||
def handle(self, *args, **options):
|
||||
MAKE_MODIFS=False
|
||||
try:
|
||||
country_to_change = 'FI'
|
||||
currency_to_change = 'EUR'
|
||||
new_rate = 25.5
|
||||
user_country_vat_rate = get_vat_rate_for_country(country_to_change)
|
||||
logger.debug("Existing VATRate for %s %s " % (country_to_change, user_country_vat_rate))
|
||||
vat_rate = VATRates.objects.get(
|
||||
territory_codes=country_to_change, start_date__isnull=False, stop_date=None
|
||||
)
|
||||
logger.debug("VAT rate for %s is %s" % (country_to_change, vat_rate.rate))
|
||||
logger.debug("vat_rate object = %s" % vat_rate)
|
||||
logger.debug("Create end date for the VATRate %s" % vat_rate.id)
|
||||
#if MAKE_MODIFS:
|
||||
# vat_rate.stop_date = datetime.date(2024, 8, 31)
|
||||
# vat_rate.save()
|
||||
# print("Creating a new VATRate for FI")
|
||||
# obj, created = VATRates.objects.get_or_create(
|
||||
# start_date=datetime.date(2024, 9, 1),
|
||||
# stop_date=None,
|
||||
# territory_codes=country_to_change,
|
||||
# currency_code=currency_to_change,
|
||||
# rate=new_rate * 0.01,
|
||||
# rate_type="standard",
|
||||
# description="FINLAND standard VAT (added manually on %s)" % datetime.datetime.now()
|
||||
# )
|
||||
# if created:
|
||||
# logger.debug("Created new VAT Rate for %s with the new rate %s" % (country_to_change, new_rate))
|
||||
# logger.debug(obj)
|
||||
# else:
|
||||
# logger.debug("VAT Rate for %s already exists with the rate %s" % (country_to_change, new_rate))
|
||||
logger.debug("Getting all subscriptions of %s that need a VAT Rate change")
|
||||
subscriptions = stripe.Subscription.list(limit=100) # Increase the limit to 100 per page (maximum)
|
||||
fi_subs = []
|
||||
|
||||
while subscriptions:
|
||||
for subscription in subscriptions:
|
||||
if len(subscription.default_tax_rates) > 0 and subscription.default_tax_rates[0].jurisdiction and subscription.default_tax_rates[0].jurisdiction.lower() == 'fi':
|
||||
fi_subs.append(subscription)
|
||||
elif len(subscription.default_tax_rates) > 0:
|
||||
print("subscription %s belongs to %s" % (subscription.id, subscription.default_tax_rates[0].jurisdiction))
|
||||
else:
|
||||
print("subscription %s does not have a tax rate" % subscription.id)
|
||||
if subscriptions.has_more:
|
||||
print("FETCHING MORE")
|
||||
subscriptions = stripe.Subscription.list(limit=100, starting_after=subscriptions.data[-1])
|
||||
else:
|
||||
break
|
||||
logger.debug("There are %s FI subscription that need VAT rate update" % len(fi_subs))
|
||||
|
||||
# CSV column headers
|
||||
csv_headers = [
|
||||
"customer_name",
|
||||
"customer_email",
|
||||
"stripe_customer_id",
|
||||
"subscription_id",
|
||||
"subscription_name",
|
||||
"amount",
|
||||
"vat_rate"
|
||||
]
|
||||
# CSV file name
|
||||
csv_filename = "fi_subscriptions_change_2024.csv"
|
||||
# Write subscription data to CSV file
|
||||
with open(csv_filename, mode='w', newline='') as csv_file:
|
||||
writer = csv.DictWriter(csv_file, fieldnames=csv_headers)
|
||||
writer.writeheader()
|
||||
|
||||
for subscription in fi_subs:
|
||||
subscription_id = subscription["id"]
|
||||
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].user.id)
|
||||
if c_user:
|
||||
customer_name = c_user.name.encode('utf-8')
|
||||
customer_email = c_user.email
|
||||
items = subscription.get("items", {}).get("data", [])
|
||||
for item in items:
|
||||
subscription_name = item.get("plan", {}).get("id", "")
|
||||
amount = item.get("plan", {}).get("amount", "")
|
||||
|
||||
# Convert amount to a proper format (e.g., cents to dollars)
|
||||
amount_in_chf = amount / 100 # Adjust this conversion as needed
|
||||
|
||||
# Writing to CSV
|
||||
writer.writerow({
|
||||
"customer_name": customer_name,
|
||||
"customer_email": customer_email,
|
||||
"stripe_customer_id": stripe_customer_id,
|
||||
"subscription_id": subscription_id,
|
||||
"subscription_name": subscription_name,
|
||||
"amount": amount_in_chf,
|
||||
"vat_rate": vat_rate # Fill in VAT rate if available
|
||||
})
|
||||
else:
|
||||
print("No customuser for %s %s" % (stripe_customer_id, subscription_id))
|
||||
|
||||
|
||||
if MAKE_MODIFS:
|
||||
print("Making modifications now")
|
||||
tax_rate_obj = stripe.TaxRate.create(
|
||||
display_name="VAT",
|
||||
description="VAT for %s" % country_to_change,
|
||||
jurisdiction=country_to_change,
|
||||
percentage=new_rate,
|
||||
inclusive=False,
|
||||
)
|
||||
stripe_tax_rate = StripeTaxRate.objects.create(
|
||||
display_name=tax_rate_obj.display_name,
|
||||
description=tax_rate_obj.description,
|
||||
jurisdiction=tax_rate_obj.jurisdiction,
|
||||
percentage=tax_rate_obj.percentage,
|
||||
inclusive=False,
|
||||
tax_rate_id=tax_rate_obj.id
|
||||
)
|
||||
|
||||
for fi_sub in fi_subs:
|
||||
fi_sub.default_tax_rates = [stripe_tax_rate.tax_rate_id]
|
||||
fi_sub.save()
|
||||
logger.debug("Default tax rate updated for %s" % fi_sub.id)
|
||||
else:
|
||||
print("Not making any modifications because MAKE_MODIFS=False")
|
||||
|
||||
except Exception as e:
|
||||
print(" *** Error occurred. Details {}".format(str(e)))
|
|
@ -87,7 +87,7 @@
|
|||
<tbody>
|
||||
{% for ho, stripe_charge_data in invs_charge %}
|
||||
<tr>
|
||||
{{ ho.id | get_line_item_from_hosting_order_charge }}
|
||||
{{ ho | get_line_item_from_hosting_order_charge }}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -1339,7 +1339,7 @@ class InvoiceListView(LoginRequiredMixin, TemplateView):
|
|||
).order_by('-created_at')
|
||||
stripe_chgs = []
|
||||
for ho in hosting_orders:
|
||||
stripe_chgs.append({ho: stripe.Charge.retrieve(ho.stripe_charge_id)})
|
||||
stripe_chgs.append({ho.id: stripe.Charge.retrieve(ho.stripe_charge_id)})
|
||||
|
||||
paginator_charges = Paginator(stripe_chgs, 10)
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue