Skip to content

Commit

Permalink
Add Talpa resolve product endpoint with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Nov 2, 2023
1 parent a9fbd91 commit e6d6c06
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 98 deletions.
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

0 comments on commit e6d6c06

Please sign in to comment.