Skip to content

Commit

Permalink
Add resolver to return the extended price list
Browse files Browse the repository at this point in the history
Refs: PV-779
  • Loading branch information
danjacob-anders committed Feb 6, 2024
1 parent a696529 commit 816ba76
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
11 changes: 9 additions & 2 deletions parking_permits/models/parking_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..constants import ParkingPermitEndType
from ..exceptions import ParkkihubiPermitError, PermitCanNotBeEnded
from ..utils import (
calc_net_price,
calc_vat_price,
diff_months_ceil,
end_date_to_datetime,
Expand Down Expand Up @@ -451,10 +452,13 @@ def get_price_list_for_extended_permit(self, month_count):
Each item consists of:
"product": product
"price": gross price
"product": product instance
"start_date": start of period
"end_date": end of period
"vat": VAT rate
"price": gross price
"net_price": net price
"vat_price": VAT price
"""

# these are unchanged
Expand Down Expand Up @@ -485,7 +489,10 @@ def get_price_list_for_extended_permit(self, month_count):
price_list.append(
{
"product": product,
"vat": product.vat,
"price": price,
"net_price": calc_net_price(price, product.vat),
"vat_price": calc_vat_price(price, product.vat),
"start_date": month_start_date,
"end_date": month_start_date + relativedelta(months=1, days=-1),
}
Expand Down
17 changes: 17 additions & 0 deletions parking_permits/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ def resolve_get_update_address_price_changes(_obj, info, address_id):
return permit_price_changes


@query.field("getExtendedPriceList")
@is_authenticated
@convert_kwargs_to_snake_case
def resolve_get_extended_permit_price_list(_obj, info, permit_id, month_count):
"""Returns the updated price list for additional months on a fixed period permit."""

customer = info.context["request"].user.customer
try:
permit = (
ParkingPermit.objects.active().filter(customer=customer).get(pk=permit_id)
)
except ParkingPermit.DoesNotExist:
raise ObjectNotFound(_("Permit not found"))

return permit.get_price_list_for_extended_permit(month_count)


@mutation.field("deleteParkingPermit")
@is_authenticated
@convert_kwargs_to_snake_case
Expand Down
10 changes: 10 additions & 0 deletions parking_permits/schema/parking_permit.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,20 @@ type PermitPriceChangeResult {
priceChanges: [PermitPriceChangeItem]!
}

type PermitExtendedPriceResult {
startDate: String!
endDate: String!
vat: Float!
price: Float!
netPrice: Float!
vatPrice: Float!
}

type Query {
profile: CustomerNode!
getPermits: [PermitNode]
getUpdateAddressPriceChanges(addressId: ID!): [PermitPriceChangeResult]
getExtendedPriceList(permitId: ID!, monthCount: Int): [PermitExtendedPriceResult]
}

enum PermitEndType {
Expand Down
31 changes: 31 additions & 0 deletions parking_permits/tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from parking_permits.resolvers import (
resolve_change_address,
resolve_extend_parking_permit,
resolve_get_extended_permit_price_list,
resolve_update_permit_vehicle,
)
from parking_permits.tests.factories.address import AddressFactory
Expand Down Expand Up @@ -384,6 +385,36 @@ def test_resolve_change_address_no_change_to_parking_zone(rf):
assert Order.objects.count() == 0


@pytest.mark.django_db()
def test_resolve_get_extended_permit_price_list(rf):
request = rf.post("/")
customer = CustomerFactory()

now = timezone.now()
permit = ParkingPermitFactory(
customer=customer,
status=ParkingPermitStatus.VALID,
contract_type=ContractType.FIXED_PERIOD,
start_time=now,
end_time=now + timedelta(days=10),
)

ProductFactory(
zone=permit.parking_zone,
type=ProductType.RESIDENT,
start_date=(now - timedelta(days=360)).date(),
end_date=(now + timedelta(days=360)).date(),
)
request.user = customer.user

info = Info(context={"request": request})

with _mock_jwt(request.user):
response = resolve_get_extended_permit_price_list(None, info, str(permit.pk), 3)

assert len(response) == 3


@pytest.mark.django_db()
def test_resolve_extend_parking_permit_ok(rf):
request = rf.post("/")
Expand Down

0 comments on commit 816ba76

Please sign in to comment.