diff --git a/payments/migrations/0008_add_new_tax_percentage.py b/payments/migrations/0008_add_new_tax_percentage.py new file mode 100644 index 000000000..1deb4fc22 --- /dev/null +++ b/payments/migrations/0008_add_new_tax_percentage.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.11 on 2024-08-17 13:04 + +from decimal import Decimal +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('payments', '0007_add_invoice_model'), + ] + + operations = [ + migrations.AlterField( + model_name='orderline', + name='tax_percentage', + field=models.DecimalField(choices=[(Decimal('0.00'), '0.00'), (Decimal('10.00'), '10.00'), (Decimal('14.00'), '14.00'), (Decimal('24.00'), '24.00'), (Decimal('25.50'), '25.50')], decimal_places=2, default=Decimal('25.50'), max_digits=5, verbose_name='tax percentage'), + ), + migrations.AlterField( + model_name='sapmaterialcode', + name='tax_percentage', + field=models.DecimalField(choices=[(Decimal('0.00'), '0.00'), (Decimal('10.00'), '10.00'), (Decimal('14.00'), '14.00'), (Decimal('24.00'), '24.00'), (Decimal('25.50'), '25.50')], decimal_places=2, default=Decimal('25.50'), max_digits=5, verbose_name='tax percentage'), + ), + ] diff --git a/payments/models.py b/payments/models.py index db8f0e78d..a06bd536b 100644 --- a/payments/models.py +++ b/payments/models.py @@ -29,10 +29,11 @@ "10.00", "14.00", "24.00", + "25.50", ) ] -DEFAULT_TAX_PERCENTAGE = Decimal("24.00") +DEFAULT_TAX_PERCENTAGE = Decimal("25.50") PRICE_PER_PERIOD = "per_period" PRICE_FIXED = "fixed" PRICE_TYPE_CHOICES = ( diff --git a/payments/providers/cpu_ceepos.py b/payments/providers/cpu_ceepos.py index 84f26a054..1bb70ec9d 100644 --- a/payments/providers/cpu_ceepos.py +++ b/payments/providers/cpu_ceepos.py @@ -150,6 +150,7 @@ def _get_order_line_description(order: Order) -> str: def _get_ceepos_tax_code(order_line: OrderLine) -> str: tax_pct = order_line.tax_percentage ceepos_tax_codes = { + 25_500_000: "255", 24_000_000: "24", 14_000_000: "14", 10_000_000: "10", @@ -158,6 +159,7 @@ def _get_ceepos_tax_code(order_line: OrderLine) -> str: # Tampere specific Ceepos tax codes in the production environment if self.url_payment_api == "https://shop.tampere.fi/maksu.html": ceepos_tax_codes = { + 25_500_000: "35", 24_000_000: "15", 14_000_000: "14", 10_000_000: "13", diff --git a/payments/tests/test_cpu_ceepos.py b/payments/tests/test_cpu_ceepos.py index 09efb7887..832c11ac0 100644 --- a/payments/tests/test_cpu_ceepos.py +++ b/payments/tests/test_cpu_ceepos.py @@ -1,6 +1,7 @@ import hmac import json from unittest import mock +from decimal import Decimal import pytest from django.http import HttpResponse @@ -324,6 +325,50 @@ def test_payload_add_products_success(payment_provider, order_with_products): assert "Description" in product +@pytest.mark.parametrize( + "tax_percentage,tax_code", + ( + (Decimal('0'), "0"), + (Decimal('10.00'), "10"), + (Decimal('14.00'), "14"), + (Decimal('24.00'), "24"), + (Decimal('25.50'), "255"), + ), +) +def test_tax_code_mapping_in_qa(payment_provider, order_with_products, tax_percentage, tax_code): + """Test the tax percentage is mapped to a correct code in qa environment""" + payload = {} + + order_with_products.order_lines.all().update(tax_percentage=tax_percentage) + payment_provider.payload_add_products(payload, order_with_products) + + for product in payload["Products"]: + assert product["Taxcode"] == tax_code + + +@pytest.mark.parametrize( + "tax_percentage,tax_code", + ( + (Decimal('0'), "18"), + (Decimal('10.00'), "13"), + (Decimal('14.00'), "14"), + (Decimal('24.00'), "15"), + (Decimal('25.50'), "35"), + ), +) +def test_tax_code_mapping_in_production(provider_base_config, order_with_products, tax_percentage, tax_code): + """Test the tax percentage is mapped to a correct code in production environment""" + provider_base_config["RESPA_PAYMENTS_CEEPOS_API_URL"] = "https://shop.tampere.fi/maksu.html" + payment_provider = CPUCeeposProvider(config=provider_base_config) + payload = {} + + order_with_products.order_lines.all().update(tax_percentage=tax_percentage) + payment_provider.payload_add_products(payload, order_with_products) + + for product in payload["Products"]: + assert product["Taxcode"] == tax_code + + def test_payload_add_customer_success(payment_provider, order_with_products): """Test the customer data from order is added correctly into payload""" payload = {} diff --git a/respa_pricing/migrations/0008_add_new_tax_percentage.py b/respa_pricing/migrations/0008_add_new_tax_percentage.py new file mode 100644 index 000000000..06be99b19 --- /dev/null +++ b/respa_pricing/migrations/0008_add_new_tax_percentage.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.11 on 2024-08-17 15:15 + +from decimal import Decimal +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('respa_pricing', '0007_auto_20231218_1250'), + ] + + operations = [ + migrations.AlterField( + model_name='eventtype', + name='tax_percentage', + field=models.DecimalField(choices=[(Decimal('0.00'), '0.00'), (Decimal('10.00'), '10.00'), (Decimal('14.00'), '14.00'), (Decimal('24.00'), '24.00'), (Decimal('25.50'), '25.50')], decimal_places=2, default=Decimal('25.50'), max_digits=5, verbose_name='tax percentage'), + ), + migrations.AlterField( + model_name='usergroup', + name='tax_percentage', + field=models.DecimalField(choices=[(Decimal('0.00'), '0.00'), (Decimal('10.00'), '10.00'), (Decimal('14.00'), '14.00'), (Decimal('24.00'), '24.00'), (Decimal('25.50'), '25.50')], decimal_places=2, default=Decimal('25.50'), max_digits=5, verbose_name='tax percentage'), + ), + ] diff --git a/respa_pricing/models/price.py b/respa_pricing/models/price.py index 1d88c66ac..1414cc7b5 100644 --- a/respa_pricing/models/price.py +++ b/respa_pricing/models/price.py @@ -23,10 +23,11 @@ "10.00", "14.00", "24.00", + "25.50", ) ] -DEFAULT_TAX_PERCENTAGE = Decimal("24.00") +DEFAULT_TAX_PERCENTAGE = Decimal("25.50") PRICE_PER_PERIOD = "per_period" PRICE_FIXED = "fixed"