diff --git a/CHANGELOG.md b/CHANGELOG.md index 18971b21..f2830f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.2.1] - 2024-09-03 + +### Added + +- Add VAT-percents to Django Admin ([305c396](https://github.com/City-of-Helsinki/parking-permits/commit/305c396091d68e49657f1299210e233678edf96b)) +- Add vat and vat_percent properties to Order ([0e6612d](https://github.com/City-of-Helsinki/parking-permits/commit/0e6612d6031d9d7ade6a7422b1e6b3ecd2a9a513)) + +### Fixed + +- Wrap accepted refund to list in email sending ([eeebdbc](https://github.com/City-of-Helsinki/parking-permits/commit/eeebdbc4355066ca15eaaaf591861eba1e2f1c02)) + ## [1.2.0] - 2024-08-30 ### Added diff --git a/parking_permits/admin.py b/parking_permits/admin.py index 529c5769..4d0891f4 100644 --- a/parking_permits/admin.py +++ b/parking_permits/admin.py @@ -210,7 +210,7 @@ class RefundAdmin(admin.ModelAdmin): "status", "created_at", "accepted_at", - "vat", + "get_vat_percent", ) list_select_related = ("order",) ordering = ("-created_at",) @@ -222,6 +222,10 @@ class RefundAdmin(admin.ModelAdmin): "permits", ) + @admin.display(description="VAT percent") + def get_vat_percent(self, obj): + return format(obj.vat_percent, ".2f") + @admin.register(Product) class ProductAdmin(admin.ModelAdmin): @@ -253,11 +257,13 @@ class OrderAdmin(admin.ModelAdmin): "address_text", "parking_zone_name", "vehicles", + "get_vat_percent", ) list_select_related = ("customer",) readonly_fields = ( "talpa_order_id", "total_payment_price", + "get_vat_percent", ) search_fields = ( "customer__last_name", @@ -273,6 +279,10 @@ class OrderAdmin(admin.ModelAdmin): ) ordering = ("-created_at",) + @admin.display(description="Vat percent") + def get_vat_percent(self, obj): + return format(obj.vat_percent, ".2f") if obj.vat_percent else None + @admin.register(OrderItem) class OrderItemAdmin(admin.ModelAdmin): @@ -284,11 +294,16 @@ class OrderItemAdmin(admin.ModelAdmin): "unit_price", "payment_unit_price", "quantity", + "get_vat_percent", ) list_select_related = ("order", "subscription", "product", "permit") readonly_fields = ("talpa_order_item_id",) ordering = ("-pk",) + @admin.display(description="Vat percent") + def get_vat_percent(self, obj): + return format(obj.vat_percentage, ".2f") + @admin.register(ParkingPermitExtensionRequest) class ParkingPermitExtensionRequestAdmin(admin.ModelAdmin): diff --git a/parking_permits/admin_resolvers.py b/parking_permits/admin_resolvers.py index 9a19edb5..842b1c51 100644 --- a/parking_permits/admin_resolvers.py +++ b/parking_permits/admin_resolvers.py @@ -1141,7 +1141,7 @@ def resolve_accept_refunds(obj, info, ids): id__in=ids, status=RefundStatus.ACCEPTED ).select_related("order__customer") for refund in accepted_refunds: - send_refund_email(RefundEmailType.ACCEPTED, refund.order.customer, refund) + send_refund_email(RefundEmailType.ACCEPTED, refund.order.customer, [refund]) return qs.count() diff --git a/parking_permits/models/order.py b/parking_permits/models/order.py index 57582b2c..819d86f9 100644 --- a/parking_permits/models/order.py +++ b/parking_permits/models/order.py @@ -1,4 +1,5 @@ import logging +from decimal import Decimal from urllib.parse import urljoin import requests @@ -510,6 +511,14 @@ def total_payment_price_net(self): def total_payment_price_vat(self): return sum([item.total_payment_price_vat for item in self.order_items.all()]) + @property + def vat(self): + return self.order_items.first().vat if self.order_items.exists() else Decimal(0) + + @property + def vat_percent(self): + return self.vat * 100 + def _cancel_talpa_order(self): headers = { "api-key": settings.TALPA_API_KEY,