Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make possible to reuse get_change_price() #189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions plans/plan_change.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding=utf-8
from decimal import Decimal
from django.conf import settings
from plans.importer import import_name


class PlanChangePolicy(object):
Expand Down Expand Up @@ -96,3 +98,24 @@ def _calculate_final_price(self, period, day_cost_diff):
return None
else:
return cost


def get_policy():
policy_class = getattr(
settings,
"PLANS_CHANGE_POLICY",
"plans.plan_change.StandardPlanChangePolicy",
)
return import_name(policy_class)()


def get_change_price(userplan, plan):
policy = get_policy()

if userplan.expire is not None:
period = userplan.days_left()
else:
# Use the default period of the new plan
period = 30

return policy.get_change_price(userplan.plan, plan, period)
22 changes: 2 additions & 20 deletions plans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from plans.signals import order_started
from plans.utils import get_currency
from plans.validators import plan_validation
from plans.plan_change import get_change_price

UserPlan = AbstractUserPlan.get_concrete_model()
PlanPricing = AbstractPlanPricing.get_concrete_model()
Expand Down Expand Up @@ -340,27 +341,8 @@ def get_all_context(self):
)
self.pricing = None

def get_policy(self):
policy_class = getattr(
settings,
"PLANS_CHANGE_POLICY",
"plans.plan_change.StandardPlanChangePolicy",
)
return import_name(policy_class)()

def get_price(self):
policy = self.get_policy()
userplan = self.request.user.userplan

if userplan.expire is not None:
period = self.request.user.userplan.days_left()
else:
# Use the default period of the new plan
period = 30

return policy.get_change_price(
self.request.user.userplan.plan, self.plan, period
)
return get_change_price(self.request.user.userplan, self.plan)

def get_context_data(self, **kwargs):
context = super(CreateOrderView, self).get_context_data(**kwargs)
Expand Down
Loading