Skip to content

Commit

Permalink
Fix #941 add vat_percentage to settings model & show including VAT wh…
Browse files Browse the repository at this point in the history
…en enabled in jesmond theme
  • Loading branch information
chrisjsimpson committed May 17, 2023
1 parent 5f7ccc8 commit 6fb0a0a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
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
12 changes: 12 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,17 @@ 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 +1124,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
24 changes: 10 additions & 14 deletions subscribie/themes/theme-jesmond/jesmond/choose.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,29 @@ <h5 class="body-lg">{{ plan.title|safe }}</h5>
<p class="py-3 body-lg">{{ plan.trial_period_days }} {{ _('days free') }}</p>
{% endif %}

{# show VAT next to the price if VAT is enabled #}
{% if setting.charge_vat|int == 1 %}
{% if plan.interval_amount|int > 0 %}
{% set recurring_VAT=plan.interval_amount * 0.20/100|round|int %}
{% set recurring_VAT=" +%.2f vat "|format(recurring_VAT) %}
{% endif %}
{% if plan.sell_price|int > 0 %}
{% set sellPrice_VAT=plan.sell_price * 0.20/100|round|int %}
{% set sellPrice_VAT=" +%.2f vat "|format(sellPrice_VAT) %}
{% endif %}
{% endif %}

{% if plan.requirements.subscription %}
<div class="my-md-4">
<span class="text">
{% if plan.trial_period_days > 0 %}{{ _('Then') }} {% endif %}
<span class="price">{{ plan.showIntervalAmount() }}{{ recurring_VAT }}</span>/{{ plan.showItervalUnit() }}
<span class="price">{{ plan.showIntervalAmount() }}</span>/{{ plan.showItervalUnit() }}
</span> <br>
{% if plan.requirements.instant_payment %}
<span class="text">{{ _('Upfront cost') }}: {{ plan.showSellPrice() }}{{ sellPrice_VAT }}</span>
<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() }}{{ sellPrice_VAT }}</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>

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


@bp.route("/set_options/<plan_uuid>", methods=["GET", "POST"])
Expand Down

0 comments on commit 6fb0a0a

Please sign in to comment.