Merge branch 'master' into feature/6561/invoices-webhook

This commit is contained in:
PCoder 2019-11-28 19:52:39 +05:30
commit 6873d901c9
25 changed files with 892 additions and 182 deletions

View file

@ -5,7 +5,7 @@ import subprocess
from oca.pool import WrongIdError
from datacenterlight.models import VMPricing
from hosting.models import UserHostingKey, VMDetail
from hosting.models import UserHostingKey, VMDetail, VATRates
from opennebula_api.serializers import VirtualMachineSerializer
logger = logging.getLogger(__name__)
@ -18,7 +18,7 @@ def get_all_public_keys(customer):
:return: A list of public keys
"""
return UserHostingKey.objects.filter(user_id=customer.id).values_list(
"public_key", flat=True)
"public_key", flat=True).distinct()
def get_or_create_vm_detail(user, manager, vm_id):
@ -150,6 +150,20 @@ def ping_ok(host_ipv6):
return True
def get_vat_rate_for_country(country):
vat_rate = None
try:
vat_rate = VATRates.objects.get(
territory_codes=country, start_date__isnull=False, stop_date=None
)
logger.debug("VAT rate for %s is %s" % (country, vat_rate.rate))
return vat_rate.rate
except VATRates.DoesNotExist as dne:
logger.debug(str(dne))
logger.debug("Did not find VAT rate for %s, returning 0" % country)
return 0
class HostingUtils:
@staticmethod
def clear_items_from_list(from_list, items_list):

View file

@ -226,7 +226,8 @@ class StripeUtils(object):
return charge
@handleStripeError
def get_or_create_stripe_plan(self, amount, name, stripe_plan_id):
def get_or_create_stripe_plan(self, amount, name, stripe_plan_id,
interval=""):
"""
This function checks if a StripePlan with the given
stripe_plan_id already exists. If it exists then the function
@ -238,6 +239,10 @@ class StripeUtils(object):
:param stripe_plan_id: The id of the Stripe plan to be
created. Use get_stripe_plan_id_string function to
obtain the name of the plan to be created
:param interval: str representing the interval of the Plan
Specifies billing frequency. Either day, week, month or year.
Ref: https://stripe.com/docs/api/plans/create#create_plan-interval
The default is month
:return: The StripePlan object if it exists else creates a
Plan object in Stripe and a local StripePlan and
returns it. Returns None in case of Stripe error
@ -245,6 +250,7 @@ class StripeUtils(object):
_amount = float(amount)
amount = int(_amount * 100) # stripe amount unit, in cents
stripe_plan_db_obj = None
plan_interval = interval if interval is not "" else self.INTERVAL
try:
stripe_plan_db_obj = StripePlan.objects.get(
stripe_plan_id=stripe_plan_id)
@ -252,7 +258,7 @@ class StripeUtils(object):
try:
self.stripe.Plan.create(
amount=amount,
interval=self.INTERVAL,
interval=plan_interval,
name=name,
currency=self.CURRENCY,
id=stripe_plan_id)