From 305c396091d68e49657f1299210e233678edf96b Mon Sep 17 00:00:00 2001 From: Mika Hietanen Date: Fri, 30 Aug 2024 13:56:11 +0300 Subject: [PATCH 1/4] Add VAT-percents to Django Admin Updates: - Add VAT to OrderItem list view - Add VAT to Order list view (get from first order item if it exists) - Add VAT to single Order view as read-only field - Format Refund VAT to two decimals Refs #PV-870 --- parking_permits/admin.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/parking_permits/admin.py b/parking_permits/admin.py index 529c5769..cc3b7d94 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,11 @@ class OrderAdmin(admin.ModelAdmin): ) ordering = ("-created_at",) + @admin.display(description="Vat percent") + def get_vat_percent(self, obj): + if obj.order_items.exists(): + return format(obj.order_items.first().vat_percentage, ".2f") + @admin.register(OrderItem) class OrderItemAdmin(admin.ModelAdmin): @@ -284,11 +295,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): From eeebdbc4355066ca15eaaaf591861eba1e2f1c02 Mon Sep 17 00:00:00 2001 From: Mika Hietanen Date: Mon, 2 Sep 2024 14:01:28 +0300 Subject: [PATCH 2/4] Wrap accepted refund to list in email sending --- parking_permits/admin_resolvers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() From 0e6612d6031d9d7ade6a7422b1e6b3ecd2a9a513 Mon Sep 17 00:00:00 2001 From: Mika Hietanen Date: Mon, 2 Sep 2024 14:22:33 +0300 Subject: [PATCH 3/4] Add vat and vat_percent properties to Order --- parking_permits/admin.py | 3 +-- parking_permits/models/order.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/parking_permits/admin.py b/parking_permits/admin.py index cc3b7d94..4d0891f4 100644 --- a/parking_permits/admin.py +++ b/parking_permits/admin.py @@ -281,8 +281,7 @@ class OrderAdmin(admin.ModelAdmin): @admin.display(description="Vat percent") def get_vat_percent(self, obj): - if obj.order_items.exists(): - return format(obj.order_items.first().vat_percentage, ".2f") + return format(obj.vat_percent, ".2f") if obj.vat_percent else None @admin.register(OrderItem) 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, From 48eb4bf137c9e799751091ecf9459bd3d3e6cd27 Mon Sep 17 00:00:00 2001 From: Mika Hietanen Date: Tue, 3 Sep 2024 11:48:20 +0300 Subject: [PATCH 4/4] Release 1.2.1 --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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