From a0888fe96684b16001e6bd4813b579012bd5b00d Mon Sep 17 00:00:00 2001 From: Reto Aebersold Date: Thu, 25 Jan 2024 10:28:30 +0100 Subject: [PATCH] feat: address rendering --- .../personalProfile/PersonalProfilePage.vue | 147 +++++++++++------- client/src/stores/user.ts | 32 ++++ server/vbv_lernwelt/core/serializers.py | 26 +++- 3 files changed, 147 insertions(+), 58 deletions(-) diff --git a/client/src/pages/personalProfile/PersonalProfilePage.vue b/client/src/pages/personalProfile/PersonalProfilePage.vue index 178e2e81..3266a9b1 100644 --- a/client/src/pages/personalProfile/PersonalProfilePage.vue +++ b/client/src/pages/personalProfile/PersonalProfilePage.vue @@ -2,10 +2,13 @@ import { useUserStore } from "@/stores/user"; import { useEntities } from "@/services/onboarding"; import { computed } from "vue"; +import { useTranslation } from "i18next-vue"; const user = useUserStore(); const { organisations } = useEntities(); +const { t } = useTranslation(); + const organisationName = computed(() => { const org = organisations.value.find((c) => c.id === user.organisation); if (org) { @@ -13,6 +16,37 @@ const organisationName = computed(() => { } return "Keine Organisation"; }); + +const privateAddress = computed(() => { + let addressText = `${user.street} ${user.street_number}`; + if (user.postal_code || user.city) { + addressText += `, ${user.postal_code} ${user.city}`; + } + if (user.country) { + addressText += `, ${user.country[`name_${user.language}`]}`; + } + + return addressText.trim(); +}); + +const orgAddress = computed(() => { + let addressText = `${user.organisation_street} ${user.organisation_street_number}`; + if (user.organisation_postal_code || user.organisation_city) { + addressText += `, ${user.organisation_postal_code} ${user.organisation_city}`; + } + if (user.organisation_country) { + addressText += `, ${user.organisation_country[`name_${user.language}`]}`; + } + + return addressText.trim(); +}); + +const invoiceAddress = computed(() => { + if (user.invoice_address === "org") { + return t("a.Gleich wie die Firmenanschrift"); + } + return t("a.Gleich wie die Privatadresse"); +}); diff --git a/client/src/stores/user.ts b/client/src/stores/user.ts index 1243cb19..e35b8624 100644 --- a/client/src/stores/user.ts +++ b/client/src/stores/user.ts @@ -18,6 +18,14 @@ if (import.meta.env.VITE_OAUTH_API_BASE_URL) { // typed state https://stackoverflow.com/questions/71012513/when-using-pinia-and-typescript-how-do-you-use-an-action-to-set-the-state export type AvailableLanguages = "de" | "fr" | "it"; +export type InvoiceAddress = "prv" | "org"; + +type Country = { + country_id: number; + name_de: string; + name_fr: string; + name_it: string; +}; export type UserState = { id: string; @@ -31,6 +39,18 @@ export type UserState = { course_session_experts: string[]; loggedIn: boolean; language: AvailableLanguages; + invoice_address: InvoiceAddress | null; + street: string | null; + street_number?: string | null; + postal_code?: string | null; + city?: string | null; + country?: Country | null; + organisation_detail_name?: string | null; + organisation_street?: string | null; + organisation_street_number?: string | null; + organisation_postal_code?: string | null; + organisation_city?: string | null; + organisation_country?: Country | null; }; let defaultLanguage: AvailableLanguages = "de"; @@ -63,6 +83,18 @@ const initialUserState: UserState = { course_session_experts: [], loggedIn: false, language: defaultLanguage, + invoice_address: "prv", + street: null, + street_number: null, + postal_code: null, + city: null, + country: null, + organisation_detail_name: null, + organisation_street: null, + organisation_street_number: null, + organisation_postal_code: null, + organisation_city: null, + organisation_country: null, }; async function setLocale(language: AvailableLanguages) { diff --git a/server/vbv_lernwelt/core/serializers.py b/server/vbv_lernwelt/core/serializers.py index 86f11fe0..871757f4 100644 --- a/server/vbv_lernwelt/core/serializers.py +++ b/server/vbv_lernwelt/core/serializers.py @@ -13,8 +13,16 @@ def create_json_from_objects(objects, serializer_class, many=True) -> str: return JSONRenderer().render(serializer.data).decode("utf-8") +class CountrySerializer(serializers.ModelSerializer): + class Meta: + model = Country + fields = "__all__" + + class UserSerializer(serializers.ModelSerializer): course_session_experts = serializers.SerializerMethodField() + country = CountrySerializer() + organisation_country = CountrySerializer() class Meta: model = User @@ -29,6 +37,18 @@ class UserSerializer(serializers.ModelSerializer): "is_superuser", "course_session_experts", "language", + "invoice_address", + "street", + "street_number", + "postal_code", + "city", + "country", + "organisation_detail_name", + "organisation_street", + "organisation_street_number", + "organisation_postal_code", + "organisation_city", + "organisation_country", ] read_only_fields = [ "id", @@ -59,9 +79,3 @@ class OrganisationSerializer(serializers.ModelSerializer): class Meta: model = Organisation fields = "__all__" - - -class CountrySerializer(serializers.ModelSerializer): - class Meta: - model = Country - fields = "__all__"