Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Talpa resolve product endpoint with tests #413

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion parking_permits/customer_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def end(
user=None,
subscription_cancel_reason=SubscriptionCancelReason.USER_CANCELLED,
cancel_from_talpa=True,
force_end=False,
):
permits = self.customer_permit_query.filter(id__in=permit_ids).order_by(
"primary_vehicle"
Expand Down Expand Up @@ -432,7 +433,7 @@ def end(
permit,
)

permit.end_permit(end_type)
permit.end_permit(end_type, force_end=force_end)
send_permit_email(
PermitEmailType.ENDED, ParkingPermit.objects.get(id=permit.id)
)
Expand Down
5 changes: 3 additions & 2 deletions parking_permits/models/parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,15 @@ def get_price_change_list(self, new_zone, is_low_emission):
)
return price_change_list

def end_permit(self, end_type):
def end_permit(self, end_type, force_end=False):
if end_type == ParkingPermitEndType.AFTER_CURRENT_PERIOD:
end_time = self.current_period_end_time
else:
end_time = max(self.start_time, timezone.now())

if (
self.primary_vehicle
not force_end
and self.primary_vehicle
and self.customer.permits.active_after(end_time)
.exclude(id=self.id)
.exists()
Expand Down
4 changes: 4 additions & 0 deletions parking_permits/models/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ def is_low_emission(self):
self.emission,
)

@property
def description(self):
return f'{_("Vehicle")}: {str(self)}'

def __str__(self):
vehicle_str = "%s" % self.registration_number or ""
if self.manufacturer:
Expand Down
17 changes: 13 additions & 4 deletions parking_permits/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ class TalpaPayloadSerializer(serializers.Serializer):


class RightOfPurchaseResponseSerializer(serializers.Serializer):
errorMessage = serializers.CharField(help_text="Error if exists", default="")
rightOfPurchase = serializers.BooleanField(help_text="Has rights to purchase")
userId = serializers.CharField(help_text="User id")
errorMessage = serializers.CharField(help_text="Error if exists", default="")


class ResolvePriceResponseSerializer(serializers.Serializer):
rowPriceNet = serializers.FloatField(help_text="Row price net")
rowPriceVat = serializers.FloatField(help_text="Row price vat")
rowPriceTotal = serializers.FloatField(help_text="Row price total")
userId = serializers.CharField(help_text="User id")
subscriptionId = serializers.CharField(help_text="Subscription id")
priceNet = serializers.FloatField(help_text="Total net price")
priceVat = serializers.FloatField(help_text="Total vat")
priceGross = serializers.FloatField(help_text="Gross price")
vatPercentage = serializers.FloatField(help_text="Vat percentage")
errorMessage = serializers.CharField(help_text="Error if exists", default="")


class ResolveProductResponseSerializer(serializers.Serializer):
userId = serializers.CharField(help_text="User id")
subscriptionId = serializers.CharField(help_text="Subscription id")
productId = serializers.FloatField(help_text="Product id")
productName = serializers.FloatField(help_text="Product name")
productLabel = serializers.FloatField(help_text="Product label")
errorMessage = serializers.CharField(help_text="Error if exists", default="")


class PaymentSerializer(serializers.Serializer):
Expand Down
Loading