Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Dec 4, 2023
2 parents b7b05d7 + 8d70ad2 commit e696cbe
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 50 deletions.
17 changes: 9 additions & 8 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-10 21:13+0200\n"
"POT-Creation-Date: 2023-12-02 15:09+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -895,6 +895,9 @@ msgstr "Viimeisin katsastuspäivä"
msgid "Update from traficom on"
msgstr "Päivitetty Traficomista"

msgid "Traficom Restrictions"
msgstr "Traficom-rajoitukset"

msgid "Not a valid customer address"
msgstr "Epäkelpo asiakkaan osoite"

Expand Down Expand Up @@ -951,13 +954,11 @@ msgstr ""
msgid "Vehicle %(registration_number)s is decommissioned"
msgstr "Ajoneuvo %(registration_number)s on liikennekäytöstäpoistettu"

msgid ""
"According to the Digital and Population Data Services Agency, you do not "
"live in the Resident parking area. If you have just moved to a Resident "
"parking area, contact Digital and Population Data Services Agency."
msgstr ""
"Digi- ja väestörekisteritietojen mukaan et asu pysäköintitunnusalueella. Jos "
"olet juuri muuttanut pysäköintitunnusalueelle, ole yhteydessä DVV:hen, dvv.fi"
msgid "The person has no driving licence"
msgstr "Henkilölle ei löydy ajokorttia"

msgid "No valid driving licence"
msgstr "Voimassaolevaa ajo-oikeutta ei löydy"

msgid "Failed to fetch data from traficom"
msgstr "Tietojen haku Traficomilta epäonnistui"
Expand Down
18 changes: 9 additions & 9 deletions locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-10 21:13+0200\n"
"POT-Creation-Date: 2023-12-02 15:09+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -892,6 +892,9 @@ msgstr "Sista besiktas dag"
msgid "Update from traficom on"
msgstr "Uppdated från Traficom"

msgid "Traficom Restrictions"
msgstr "Traficom restriktioner"

msgid "Not a valid customer address"
msgstr "Inte en giltig kundadress"

Expand Down Expand Up @@ -949,14 +952,11 @@ msgstr ""
msgid "Vehicle %(registration_number)s is decommissioned"
msgstr "Fordonet %(registration_number)s är avställd"

msgid ""
"According to the Digital and Population Data Services Agency, you do not "
"live in the Resident parking area. If you have just moved to a Resident "
"parking area, contact Digital and Population Data Services Agency."
msgstr ""
"Enligt Myndigheten för digitalisering och befolkningsdata bor du inte i "
"boendeparkering zone. Om du precis har flyttat till ett boendeparkering "
"zone, kontakta Myndigheten för digitalisering och befolkningsdata."
msgid "The person has no driving licence"
msgstr "Personen har inget körkort"

msgid "No valid driving licence"
msgstr "Giltig körrätt saknas"

msgid "Failed to fetch data from traficom"
msgstr "Datahämtning från Traficomilta misslyckades"
Expand Down
11 changes: 7 additions & 4 deletions parking_permits/customer_permit.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def get(self):
vehicle = permit.vehicle
# Update vehicle detail from traficom if it wasn't updated today
if permit.vehicle.updated_from_traficom_on < tz.localdate(tz.now()):
self.customer.fetch_vehicle_detail(vehicle.registration_number)
vehicle = self.customer.fetch_vehicle_detail(
vehicle.registration_number
)

user_of_vehicle = self.customer.is_user_of_vehicle(vehicle)
if not user_of_vehicle:
Expand Down Expand Up @@ -242,6 +244,7 @@ def create(self, address_id, registration):
ParkingPermitEventFactory.make_create_permit_event(
permit, created_by=self.customer.user
)

return permit

def delete(self, permit_id):
Expand Down Expand Up @@ -493,13 +496,13 @@ def _calculate_prices(self, permit, product_with_qty):
base_price = unit_price = product.unit_price
discount_price = base_price - (product.low_emission_discount * base_price)

if permit.vehicle.is_low_emission:
unit_price = discount_price

if not permit.primary_vehicle:
increase = decimal.Decimal(SECONDARY_VEHICLE_PRICE_INCREASE) / 100
unit_price += increase * unit_price

if permit.vehicle.is_low_emission:
unit_price = discount_price

product.base_price = base_price
product.discount_price = discount_price
product.quantity = quantity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ class Command(BaseCommand):
def handle(self, *args, **options):
call_command("import_parking_zones")
call_command("create_test_address")
call_command(
"create_parking_zone_products",
start_date="2023-06-01",
end_date="2023-11-30",
price_increment_factor_old_zone=1.5,
price_increment_factor_new_zone=2.0,
low_emission_discount_old_zone=0.3333,
low_emission_discount_new_zone=0.25,
)
call_command(
"create_parking_zone_products",
start_date="2023-12-01",
Expand Down
23 changes: 23 additions & 0 deletions parking_permits/migrations/0044_add_vehicle_restrictions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.1 on 2023-11-30 11:26

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("parking_permits", "0043_alter_subscription_cancel_reason"),
]

operations = [
migrations.AddField(
model_name="vehicle",
name="restrictions",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(blank=True, max_length=2),
default=list,
size=None,
verbose_name="Traficom Restrictions",
),
),
]
7 changes: 7 additions & 0 deletions parking_permits/models/vehicle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.gis.db import models
from django.contrib.postgres.fields import ArrayField
from django.utils import timezone as tz
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -160,6 +161,12 @@ class Vehicle(TimestampedModelMixin):
VehicleUser, verbose_name=_("Vehicle users"), related_name="vehicles"
)

restrictions = ArrayField(
verbose_name=_("Traficom Restrictions"),
base_field=models.CharField(max_length=2, blank=True),
default=list,
)

class Meta:
verbose_name = _("Vehicle")
verbose_name_plural = _("Vehicles")
Expand Down
1 change: 1 addition & 0 deletions parking_permits/schema/parking_permit.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type VehicleNode {
registrationNumber: String
emission: Int
isLowEmission: Boolean
restrictions: [String]
}

type ProductNode {
Expand Down
1 change: 1 addition & 0 deletions parking_permits/schema/parking_permit_admin.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type VehicleNode {
emission: Int
emissionType: String
powerType: VehiclePowerTypeNode
restrictions: [String]
}

type AnnouncementNode {
Expand Down
65 changes: 48 additions & 17 deletions parking_permits/services/traficom.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,32 @@

logger = logging.getLogger("db")


VEHICLE_RESTRICTIONS = (
"03",
"07",
"10",
"11",
"18",
"20",
"22",
"23",
"24",
"25",
"34",
)

# these codes will raise an error and prevent adding a permit
BLOCKING_VEHICLE_RESTRICTIONS = ("18", "19")

CONSUMPTION_TYPE_NEDC = "4"
CONSUMPTION_TYPE_WLTP = "10"
DECOMMISSIONED_VEHICLE_RESTRICTION_TYPE = "18"
VEHICLE_TYPE = 1
LIGHT_WEIGHT_VEHICLE_TYPE = 2
VEHICLE_SEARCH = 841
DRIVING_LICENSE_SEARCH = 890
NO_DRIVING_LICENSE_ERROR_CODE = "562"
NO_VALID_DRIVING_LICENSE_ERROR_CODE = "578"

POWER_TYPE_MAPPER = {
"01": "Bensin",
Expand Down Expand Up @@ -89,17 +108,25 @@ def fetch_vehicle_details(self, registration_number):
}
)

restrictions = et.findall(".//rajoitustiedot/rajoitustieto")
for r in restrictions:
restriction_type = r.find("rajoitusLaji").text
if restriction_type == DECOMMISSIONED_VEHICLE_RESTRICTION_TYPE:
restrictions = []

for restriction in et.findall(".//rajoitustiedot/rajoitustieto"):
try:
restriction_type = restriction.find("rajoitusLaji").text
except AttributeError:
continue

if restriction_type in BLOCKING_VEHICLE_RESTRICTIONS:
raise TraficomFetchVehicleError(
_("Vehicle %(registration_number)s is decommissioned")
% {
"registration_number": registration_number,
}
)

if restriction_type in VEHICLE_RESTRICTIONS:
restrictions.append(restriction_type)

vehicle_identity = et.find(".//tunnus")
motor = et.find(".//moottori")
owners_et = et.findall(".//omistajatHaltijat/omistajaHaltija")
Expand Down Expand Up @@ -152,29 +179,33 @@ def fetch_vehicle_details(self, registration_number):
"last_inspection_date": last_inspection_date.text
if last_inspection_date is not None
else None,
"restrictions": restrictions or [],
}
vehicle_users = []
for user_nin in user_ssns:
user = VehicleUser.objects.get_or_create(national_id_number=user_nin)
vehicle_users.append(user[0])
vehicle = Vehicle.objects.update_or_create(
registration_number=registration_number, defaults=vehicle_details
)
vehicle[0].users.set(vehicle_users)
return vehicle[0]
)[0]
vehicle.users.set(vehicle_users)
return vehicle

def fetch_driving_licence_details(self, hetu):
error_code = None
et = self._fetch_info(hetu=hetu)
driving_licence_et = et.find(".//ajokorttiluokkatieto")
if driving_licence_et.find("ajooikeusluokat") is None:
raise TraficomFetchVehicleError(
_(
"According to the Digital and Population Data Services Agency, "
"you do not live in the Resident parking area. "
"If you have just moved to a Resident parking area, "
"contact Digital and Population Data Services Agency."
)
)
try:
error_code = et.find(".//yleinen/virhe/virhekoodi").text
except AttributeError:
pass
if error_code == NO_DRIVING_LICENSE_ERROR_CODE:
raise TraficomFetchVehicleError(_("The person has no driving licence"))
if (
error_code == NO_VALID_DRIVING_LICENSE_ERROR_CODE
or driving_licence_et.find("ajooikeusluokat") is None
):
raise TraficomFetchVehicleError(_("No valid driving licence"))

driving_licence_categories_et = driving_licence_et.findall(
"viimeisinajooikeus/ajooikeusluokka"
Expand Down
6 changes: 3 additions & 3 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DEBUG=(bool, False),
DJANGO_SECRET_KEY=(str, ""),
ALLOWED_HOSTS=(list, ["*"]),
CORS_ALLOWED_ORIGINS=(list, ["http://localhost:3000"]),
CSRF_TRUSTED_ORIGINS=(list, ["https://*.hel.fi", "https://*.hel.ninja"]),
DATABASE_URL=(str, "sqlite:////tmp/my-tmp-sqlite.db"),
TALPA_NAMESPACE=(str, "asukaspysakointi"),
Expand Down Expand Up @@ -213,9 +214,8 @@
TRAFICOM_VERIFY_SSL = env("TRAFICOM_VERIFY_SSL")
TRAFICOM_CHECK = env("TRAFICOM_CHECK")

# cors
CORS_ORIGIN_ALLOW_ALL = True

# CORS
CORS_ALLOWED_ORIGINS = env("CORS_ALLOWED_ORIGINS")
CORS_ALLOW_HEADERS = list(default_headers) + [
"x-authorization", # for passing Helsinki Profile API token form frontend
]
Expand Down

0 comments on commit e696cbe

Please sign in to comment.