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

Fix #941 show VAT for the plans in the homepage #979

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""add vat_percentage to settings model

Revision ID: 34ce0963d783
Revises: 7640c2a9be5b
Create Date: 2023-05-17 18:56:11.575557

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text


# revision identifiers, used by Alembic.
revision = "34ce0963d783"
down_revision = "7640c2a9be5b"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"setting",
sa.Column(
"vat_percentage", sa.Float(), nullable=True, server_default=text("20.0")
),
)


def downgrade():
pass
20 changes: 20 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,25 @@ def calculatePrice(
f"after apply_rules interval_amount is: {interval_amount}"
) # noqa: E501

# If VAT is enabled, include VAT
settings = Setting.query.first()
if settings.charge_vat:
log.debug(f"Calculating VAT for plan {self.title}")
if self.requirements.instant_payment:
log.debug(
"Applying VAT for instant_payment amount on plan {self.title}"
) # noqa: E501
sell_price = sell_price + (
sell_price * (settings.vat_percentage / 100)
) # noqa: E501
if self.requirements.subscription:
log.debug(
"Applying VAT for interval_amount amount on plan {self.title}"
) # noqa: E501
interval_amount = interval_amount + (
interval_amount * (settings.vat_percentage / 100)
) # noqa: E501

return sell_price, interval_amount

sell_price, interval_amount = calculatePrice(
Expand Down Expand Up @@ -1113,6 +1132,7 @@ class Setting(database.Model):
id = database.Column(database.Integer(), primary_key=True)
reply_to_email_address = database.Column(database.String())
charge_vat = database.Column(database.Boolean(), default=False)
vat_percentage = database.Column(database.Float(), default=20.0)
custom_code = database.Column(database.String(), default=None)
default_currency = database.Column(database.String(), default=None)
default_country_code = database.Column(database.String(), default=None)
Expand Down
12 changes: 11 additions & 1 deletion subscribie/themes/theme-jesmond/jesmond/choose.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ <h5 class="body-lg">{{ plan.title|safe }}</h5>
{% if plan.trial_period_days > 0 %}
<p class="py-3 body-lg">{{ plan.trial_period_days }} {{ _('days free') }}</p>
{% endif %}


{% if plan.requirements.subscription %}
<div class="my-md-4">
<span class="text">
Expand All @@ -69,14 +71,22 @@ <h5 class="body-lg">{{ plan.title|safe }}</h5>
{% if plan.requirements.instant_payment %}
<span class="text">{{ _('Upfront cost') }}: {{ plan.showSellPrice() }}</span>
{% endif %}
{% if settings.charge_vat %}
<p class="text">{{ _('Including VAT') }}</span>
{% endif %}

</div>
{% else %} {# Not a subscription based product #}
<div class="my-md-4">
<span class="text">
<span class="price">{{ plan.showSellPrice() }}</span>/{{ _('One-off') }}
</span> <br>
</span> <br />
{% if settings.charge_vat %}
<p class="text">{{ _('Including VAT') }}</span><br />
{% endif %}
<span class="text">{{ _('No subscription') }}</span>
</div>

{% endif %}

{% for sellingPoint in plan.selling_points%}
Expand Down
4 changes: 2 additions & 2 deletions subscribie/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ def stats():
def choose():
# Note: Categories link to plans (via category.plans)
categories = Category.query.order_by(Category.position).all()
return render_template("choose.html", categories=categories)
settings = Setting.query.first()
return render_template("choose.html", categories=categories, settings=settings)


@bp.route("/set_options/<plan_uuid>", methods=["GET", "POST"])
def set_options(plan_uuid):
plan = Plan.query.filter_by(uuid=plan_uuid).first()

if request.method == "POST":
# Store chosen options in session
session["chosen_option_ids"] = []
Expand Down