diff --git a/rowers/credits.py b/rowers/credits.py index 30d7a279..e57710c9 100644 --- a/rowers/credits.py +++ b/rowers/credits.py @@ -1,4 +1,3 @@ -from rowers.models import Rower class InsufficientCreditError(Exception): """Raised when trying to subtract more than available""" @@ -24,3 +23,19 @@ def withdraw(amount, rower): return rower.eurocredits return rower.eurocredits + +def discount(amount,rower): + if amount < rower.eurocredits: + return amount + else: + return rower.eurocredits + + return 0 + +def discounted(amount,rower): + if amount > rower.eurocredits: + return amount-rower.eurocredits + else: + return 0 + + return 0 diff --git a/rowers/templates/instantplans.html b/rowers/templates/instantplans.html index 6176d9b9..2506fc8c 100644 --- a/rowers/templates/instantplans.html +++ b/rowers/templates/instantplans.html @@ -10,11 +10,19 @@
  • +

    On this page, you find trusted training plans that work. If you are looking for a plan, this page is for you. This ever growing list of plans contains a plan for everyone, whether you are a beginning rower or experienced, irrespective of your current fitness level. Click on a plan to read more and see the sessions. If you're on a Self-Coach plan or higher, you can get the plan including even more detailed workout instructions copied straight to your training calendar on this site, with the simple click of a button. +

    + {% if rower.eurocredits %} +

    + Your have discount vouchers for an mount of {{ rower.eurocredits }}€. You + will get discount for up to this amount on any paid plan. +

    + {% endif %}
  • {% for plan in plans %}
  • @@ -34,6 +42,10 @@ {% else %}

    Price: {{ plan.price }}€

    {% endif %} + {% if rower.eurocredits and plan.price > 0 %} +

    Your discount: {{ plan.price|discount:rower }}€

    +

    You pay: {{ plan.price|discounted:rower }}€

    + {% endif %}
  • {% endfor %} diff --git a/rowers/templates/rower_form.html b/rowers/templates/rower_form.html index d83d8a59..68096f27 100644 --- a/rowers/templates/rower_form.html +++ b/rowers/templates/rower_form.html @@ -52,6 +52,12 @@ {% endif %} {{ rower.planexpires }} + {% if rower.eurocredits %} + + Discount voucher for training plans + {{ rower.eurocredits }}€ + + {% endif %} {% endif %} {% csrf_token %} diff --git a/rowers/templatetags/rowerfilters.py b/rowers/templatetags/rowerfilters.py index 5b39f2a9..d51f18ac 100644 --- a/rowers/templatetags/rowerfilters.py +++ b/rowers/templatetags/rowerfilters.py @@ -19,6 +19,7 @@ from rowers.plannedsessions import ( race_can_register, race_can_submit,race_rower_status ) +from rowers import credits from rowers import c2stuff from rowers.c2stuff import c2_open from rowers.rower_rules import is_coach_user, is_workout_user, isplanmember,ispromember @@ -153,6 +154,15 @@ def weekbegin(nr): return True return False +@register.filter +def discount(amount,rower): + return credits.discount(amount,rower) + + +@register.filter +def discounted(amount,rower): + return credits.discounted(amount,rower) + @register.filter def weekend(nr): week, day = divmod(nr,7) diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz index f4f27297..ff0f7645 100644 Binary files a/rowers/tests/testdata/testdata.tcx.gz and b/rowers/tests/testdata/testdata.tcx.gz differ