diff --git a/migrations/versions/34ce0963d783_add_vat_percentage_to_settings_model.py b/migrations/versions/34ce0963d783_add_vat_percentage_to_settings_model.py new file mode 100644 index 00000000..b3d490cd --- /dev/null +++ b/migrations/versions/34ce0963d783_add_vat_percentage_to_settings_model.py @@ -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 diff --git a/subscribie/models.py b/subscribie/models.py index f47cbf38..aae36c9f 100644 --- a/subscribie/models.py +++ b/subscribie/models.py @@ -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( @@ -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) diff --git a/subscribie/themes/theme-jesmond/jesmond/choose.html b/subscribie/themes/theme-jesmond/jesmond/choose.html index c2b98870..3f7587be 100644 --- a/subscribie/themes/theme-jesmond/jesmond/choose.html +++ b/subscribie/themes/theme-jesmond/jesmond/choose.html @@ -61,33 +61,29 @@
{{ plan.trial_period_days }} {{ _('days free') }}
{% 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 %}{{ _('Including VAT') }} {% endif %} +
{{ _('Including VAT') }}
+ {% endif %}
{{ _('No subscription') }}