diff --git a/lib/teslamate/locations/geo_fence.ex b/lib/teslamate/locations/geo_fence.ex index 7c4ec2d8..c18bdfe3 100644 --- a/lib/teslamate/locations/geo_fence.ex +++ b/lib/teslamate/locations/geo_fence.ex @@ -12,6 +12,7 @@ defmodule TeslaMate.Locations.GeoFence do field :radius, :float field :cost_per_kwh, :decimal + field :session_fee, :decimal many_to_many :sleep_mode_whitelist, Car, join_through: "geofence_sleep_mode_whitelist", @@ -36,13 +37,15 @@ defmodule TeslaMate.Locations.GeoFence do :radius, :latitude, :longitude, - :cost_per_kwh + :cost_per_kwh, + :session_fee ]) |> put_assoc_if(attrs, :sleep_mode_blacklist) |> put_assoc_if(attrs, :sleep_mode_whitelist) |> validate_required([:name, :latitude, :longitude, :radius]) |> validate_number(:radius, greater_than: 0, less_than: 5000) |> validate_number(:cost_per_kwh, greater_than_or_equal_to: 0) + |> validate_number(:session_fee, greater_than_or_equal_to: 0) end defp put_assoc_if(changeset, attrs, key) do diff --git a/lib/teslamate/log.ex b/lib/teslamate/log.ex index dab1a85f..f6ba745f 100644 --- a/lib/teslamate/log.ex +++ b/lib/teslamate/log.ex @@ -493,13 +493,20 @@ defmodule TeslaMate.Log do 0.0 {%{charge_energy_used: kwh_used, charge_energy_added: kwh_added}, - %CP{geofence: %GeoFence{cost_per_kwh: %Decimal{} = cost_per_kwh}}} + %CP{geofence: %GeoFence{cost_per_kwh: cost_per_kwh, session_fee: session_fee}}} when is_number(kwh_added) or is_number(kwh_used) -> - [kwh_added, kwh_used] - |> Enum.reject(&is_nil/1) - |> Enum.max() - |> Decimal.from_float() - |> Decimal.mult(cost_per_kwh) + cost = + with %Decimal{} <- cost_per_kwh do + [kwh_added, kwh_used] + |> Enum.reject(&is_nil/1) + |> Enum.max() + |> Decimal.from_float() + |> Decimal.mult(cost_per_kwh) + end + + if match?(%Decimal{}, cost) or match?(%Decimal{}, session_fee) do + Decimal.add(session_fee || 0, cost || 0) + end {_, _} -> nil diff --git a/lib/teslamate_web/templates/geo_fence/form.html.leex b/lib/teslamate_web/templates/geo_fence/form.html.leex index d3ca0653..e10c557a 100644 --- a/lib/teslamate_web/templates/geo_fence/form.html.leex +++ b/lib/teslamate_web/templates/geo_fence/form.html.leex @@ -52,7 +52,7 @@ -
+
<%= label class: "label" do gettext("Cost per kWh") end %>
@@ -73,6 +73,26 @@
+
+ <%= label class: "label" do gettext("Session fee") end %> +
+
+
+
+ <%= text_input f, :session_fee, class: "input", + type: :number, inputmode: :decimal, min: 0.0, step: 0.01, + placeholder: "0.00", + phx_hook: "SetLangAttr" + %> +
+ <%= if @show_errors do %> +

<%= error_tag(f, :session_fee) %>

+ <% end %> +
+
+
+ +
<%= label class: "label" do gettext("Sleep Mode Enabled") end %>
diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index e224936e..8273ae67 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -126,7 +126,7 @@ msgstr "Einheiten" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "Zurück" @@ -136,7 +136,7 @@ msgid "Geo-Fences" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "Geo-Fence \"%{name}\" erstellt" @@ -152,32 +152,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "Leerlaufzeit vor dem Einschlafversuch" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "Speichern" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "Speichere..." @@ -396,12 +395,12 @@ msgid "Sleep Mode" msgstr "Schlafmodus" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "Geo-Fence \"%{name}\" aktualisiert" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "Schlafmodus aktiviert" @@ -483,7 +482,7 @@ msgstr[0] "%{count} Datei gefunden" msgstr[1] "%{count} Dateien gefunden" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "Spenden" @@ -513,7 +512,7 @@ msgid "Email address" msgstr "E-Mail-Adresse" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "Kosten pro kWh" @@ -531,3 +530,8 @@ msgstr "Gratis Supercharger-Nutzung" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "Allgemeine Einstellungen" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "Sessionpreis" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 98eeff91..50560153 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -125,7 +125,7 @@ msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "" @@ -135,7 +135,7 @@ msgid "Geo-Fences" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "" @@ -151,32 +151,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "" @@ -395,12 +394,12 @@ msgid "Sleep Mode" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "" @@ -482,7 +481,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "" @@ -512,7 +511,7 @@ msgid "Email address" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "" @@ -530,3 +529,8 @@ msgstr "" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 4f4c437d..6cc1c3e2 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -126,7 +126,7 @@ msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "" @@ -136,7 +136,7 @@ msgid "Geo-Fences" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "" @@ -152,32 +152,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "" @@ -396,12 +395,12 @@ msgid "Sleep Mode" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "" @@ -483,7 +482,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "" @@ -513,7 +512,7 @@ msgid "Email address" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "" @@ -531,3 +530,8 @@ msgstr "" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/default.po b/priv/gettext/fr/LC_MESSAGES/default.po index 4666650a..32baa2cb 100644 --- a/priv/gettext/fr/LC_MESSAGES/default.po +++ b/priv/gettext/fr/LC_MESSAGES/default.po @@ -125,7 +125,7 @@ msgstr "Unités" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "Retour" @@ -135,7 +135,7 @@ msgid "Geo-Fences" msgstr "Géo-repérage" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "Géo-repérage \"%{name}\" créé" @@ -151,32 +151,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "Temps d'inactivité avant d'essayer de dormir" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "Nom" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "Position" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "Rayon" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "Enregistrer" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "Enregistrement..." @@ -395,12 +394,12 @@ msgid "Sleep Mode" msgstr "Mode veille" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "Géo-repérage \"%{name}\" mis à jour" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "Mode veille activé" @@ -482,7 +481,7 @@ msgstr[0] "Trouvé %{count} fichier" msgstr[1] "Trouvé %{count} fichiers" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "Faire un don" @@ -512,7 +511,7 @@ msgid "Email address" msgstr "Adresse e-mail" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "Coût par kWh" @@ -530,3 +529,8 @@ msgstr "Supercharge gratuite" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "Réglages généraux" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "Prix fixe" diff --git a/priv/gettext/nb/LC_MESSAGES/default.po b/priv/gettext/nb/LC_MESSAGES/default.po index c4e8e678..a3e0db13 100644 --- a/priv/gettext/nb/LC_MESSAGES/default.po +++ b/priv/gettext/nb/LC_MESSAGES/default.po @@ -126,7 +126,7 @@ msgstr "Enheter" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "Tilbake" @@ -136,7 +136,7 @@ msgid "Geo-Fences" msgstr "Geo-lokasjoner" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "Geo-lokasjon \"%{name}\" opprettet" @@ -152,32 +152,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "Inaktiv tid før dvale starter" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "Navn" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "Posisjon" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "Radius" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "Lagre" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "Lagrer..." @@ -396,12 +395,12 @@ msgid "Sleep Mode" msgstr "Dvalemodus" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "Geo-lokasjon \"%{name}\" oppdatert" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "Dvalemodus aktivert" @@ -483,7 +482,7 @@ msgstr[0] "%{count} fil" msgstr[1] "%{count} filer" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "Donere" @@ -513,7 +512,7 @@ msgid "Email address" msgstr "Epost" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "Kost per kWh" @@ -531,3 +530,8 @@ msgstr "Gratis Supercharging" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "Generelle innstillinger" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "" diff --git a/priv/gettext/nb/LC_MESSAGES/errors.po b/priv/gettext/nb/LC_MESSAGES/errors.po index af487bea..ddc3305c 100644 --- a/priv/gettext/nb/LC_MESSAGES/errors.po +++ b/priv/gettext/nb/LC_MESSAGES/errors.po @@ -57,8 +57,8 @@ msgstr[1] "bør være %{count} karakterer" msgid "should have %{count} item(s)" msgid_plural "should have %{count} item(s)" -msgstr[1] "bør ha %{count} punkt" msgstr[0] "bør ha %{count} punkter" +msgstr[1] "bør ha %{count} punkt" msgid "should be at least %{count} character(s)" msgid_plural "should be at least %{count} character(s)" diff --git a/priv/gettext/sv/LC_MESSAGES/default.po b/priv/gettext/sv/LC_MESSAGES/default.po index 517a5c64..48e11682 100644 --- a/priv/gettext/sv/LC_MESSAGES/default.po +++ b/priv/gettext/sv/LC_MESSAGES/default.po @@ -126,7 +126,7 @@ msgstr "Enheter" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:108 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:131 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:137 msgid "Back" msgstr "Tillbaka" @@ -136,7 +136,7 @@ msgid "Geo-Fences" msgstr "" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:213 +#: lib/teslamate_web/live/geofence_live/form.ex:172 msgid "Geo-fence \"%{name}\" created" msgstr "Geo-Fence \"%{name}\" skapat" @@ -152,32 +152,31 @@ msgid "Idle Time Before Trying to Sleep" msgstr "Inaktiv tid innan för att försöka sova" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:45 -#: lib/teslamate_web/templates/geo_fence/index.html.leex:21 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:41 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:46 lib/teslamate_web/templates/geo_fence/index.html.leex:21 msgid "Name" msgstr "Namn" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:19 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:17 #: lib/teslamate_web/templates/geo_fence/index.html.leex:22 msgid "Position" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:56 #: lib/teslamate_web/templates/geo_fence/index.html.leex:23 msgid "Radius" msgstr "Radie" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:111 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 msgid "Save" msgstr "Spara" #, elixir-format #: lib/teslamate_web/templates/charge/cost.html.leex:112 -#: lib/teslamate_web/templates/geo_fence/form.html.leex:134 lib/teslamate_web/templates/signin/index.html.leex:33 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:140 lib/teslamate_web/templates/signin/index.html.leex:33 msgid "Saving..." msgstr "Sparar..." @@ -396,12 +395,12 @@ msgid "Sleep Mode" msgstr "Viloläge" #, elixir-format -#: lib/teslamate_web/live/geofence_live/form.ex:214 +#: lib/teslamate_web/live/geofence_live/form.ex:173 msgid "Geo-fence \"%{name}\" updated" msgstr "Geo-Fence \"%{name}\" uppdaterad" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:91 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:97 msgid "Sleep Mode Enabled" msgstr "Viloläge aktiverad" @@ -483,7 +482,7 @@ msgstr[0] "%{count} fil hittades" msgstr[1] "%{count} filer hittades" #, elixir-format -#: lib/teslamate_web/templates/layout/app.html.eex:84 +#: lib/teslamate_web/templates/layout/app.html.eex:87 msgid "Donate" msgstr "Donera" @@ -513,7 +512,7 @@ msgid "Email address" msgstr "E-postadress" #, elixir-format -#: lib/teslamate_web/templates/geo_fence/form.html.leex:71 +#: lib/teslamate_web/templates/geo_fence/form.html.leex:57 msgid "Cost per kWh" msgstr "Kostnad per kWh" @@ -531,3 +530,8 @@ msgstr "Gratis Supercharging" #: lib/teslamate_web/templates/settings/index.html.leex:140 msgid "General Settings" msgstr "Allmänna Inställningar" + +#, elixir-format +#: lib/teslamate_web/templates/geo_fence/form.html.leex:77 +msgid "Session fee" +msgstr "" diff --git a/priv/gettext/sv/LC_MESSAGES/errors.po b/priv/gettext/sv/LC_MESSAGES/errors.po index 65245aec..48902852 100644 --- a/priv/gettext/sv/LC_MESSAGES/errors.po +++ b/priv/gettext/sv/LC_MESSAGES/errors.po @@ -57,8 +57,8 @@ msgstr[1] "bör vara %{count} tecken" msgid "should have %{count} item(s)" msgid_plural "should have %{count} item(s)" -msgstr[1] "bör ha %{count} artikel" msgstr[0] "bör ha %{count} artiklar" +msgstr[1] "bör ha %{count} artikel" msgid "should be at least %{count} character(s)" msgid_plural "should be at least %{count} character(s)" diff --git a/priv/repo/migrations/20200306133847_add_flat_fee.exs b/priv/repo/migrations/20200306133847_add_flat_fee.exs new file mode 100644 index 00000000..9d1583a7 --- /dev/null +++ b/priv/repo/migrations/20200306133847_add_flat_fee.exs @@ -0,0 +1,9 @@ +defmodule TeslaMate.Repo.Migrations.AddFlatFee do + use Ecto.Migration + + def change do + alter table(:geofences) do + add(:session_fee, :decimal, precision: 6, scale: 2) + end + end +end diff --git a/test/teslamate/locations/geofences_test.exs b/test/teslamate/locations/geofences_test.exs index ee73c9c6..aabbc33e 100644 --- a/test/teslamate/locations/geofences_test.exs +++ b/test/teslamate/locations/geofences_test.exs @@ -10,14 +10,16 @@ defmodule TeslaMate.LocationsGeofencesTest do latitude: 52.514521, longitude: 13.350144, radius: 42, - cost_per_kwh: nil + cost_per_kwh: nil, + session_fee: nil } @update_attrs %{ name: "bar", latitude: 53.514521, longitude: 14.350144, radius: 43, - cost_per_kwh: 0.0079 + cost_per_kwh: 0.0079, + session_fee: 5.0 } @invalid_attrs %{ name: nil, @@ -25,6 +27,7 @@ defmodule TeslaMate.LocationsGeofencesTest do longitude: nil, radius: nil, cost_per_kwh: -0.01, + session_fee: -0.01, sleep_mode_whitelist: nil, sleep_mode_blacklist: nil } @@ -52,6 +55,7 @@ defmodule TeslaMate.LocationsGeofencesTest do assert geofence.longitude == 13.350144 assert geofence.radius == 42 assert geofence.cost_per_kwh == nil + assert geofence.session_fee == nil geofence = Repo.preload(geofence, [:sleep_mode_whitelist, :sleep_mode_blacklist]) assert geofence.sleep_mode_blacklist == [] assert geofence.sleep_mode_whitelist == [] @@ -65,7 +69,8 @@ defmodule TeslaMate.LocationsGeofencesTest do longitude: ["can't be blank"], name: ["can't be blank"], radius: ["can't be blank"], - cost_per_kwh: ["must be greater than or equal to 0"] + cost_per_kwh: ["must be greater than or equal to 0"], + session_fee: ["must be greater than or equal to 0"] } assert {:error, %Ecto.Changeset{} = changeset} = @@ -147,13 +152,19 @@ defmodule TeslaMate.LocationsGeofencesTest do assert geofence.longitude == 14.350144 assert geofence.radius == 43 assert geofence.cost_per_kwh == Decimal.from_float(0.0079) + assert geofence.session_fee == Decimal.from_float(5.00) assert geofence.sleep_mode_blacklist == [car] assert geofence.sleep_mode_whitelist == [car] assert {:ok, %GeoFence{} = geofence} = - Locations.update_geofence(geofence, %{cost_per_kwh: nil, sleep_mode_whitelist: []}) + Locations.update_geofence(geofence, %{ + cost_per_kwh: nil, + session_fee: nil, + sleep_mode_whitelist: [] + }) assert geofence.cost_per_kwh == nil + assert geofence.session_fee == nil assert geofence.sleep_mode_blacklist == [car] assert geofence.sleep_mode_whitelist == [] end diff --git a/test/teslamate/log/log_charging_test.exs b/test/teslamate/log/log_charging_test.exs index f86fdab6..30160496 100644 --- a/test/teslamate/log/log_charging_test.exs +++ b/test/teslamate/log/log_charging_test.exs @@ -377,7 +377,7 @@ defmodule TeslaMate.LogChargingTest do assert {:ok, %ChargingProcess{geofence_id: ^id}} = Log.complete_charging_process(cproc) end - test "calculates the charge costs based on the fees entered" do + test "calculates the charge costs based on the kwh fee" do car = car_fixture() assert %GeoFence{id: id} = @@ -403,7 +403,7 @@ defmodule TeslaMate.LogChargingTest do assert cproc.cost == Decimal.new("3.192500") end - test "charge cost can be zero" do + test "calculates the charge costs based on the session fee" do car = car_fixture() assert %GeoFence{id: id} = @@ -411,7 +411,61 @@ defmodule TeslaMate.LogChargingTest do latitude: 50.1121, longitude: 11.597, radius: 50, - cost_per_kwh: 0.0 + session_fee: 7.00 + }) + + assert {:ok, cproc} = + log_charging_process(charges_fixture(:phases_nil), + car: car, + attrs: %{ + date: DateTime.utc_now(), + latitude: 50.112198, + longitude: 11.597669 + } + ) + + assert cproc.charge_energy_added == 12.77 + assert cproc.charge_energy_used == 12.455230833333333 + assert cproc.cost == Decimal.new("7.00") + end + + test "calculates the charge costs based on the session fee and energy used" do + car = car_fixture() + + assert %GeoFence{id: id} = + geofence_fixture(%{ + latitude: 50.1121, + longitude: 11.597, + radius: 50, + cost_per_kwh: 0.25, + session_fee: 4.79 + }) + + assert {:ok, cproc} = + log_charging_process(charges_fixture(:phases_nil), + car: car, + attrs: %{ + date: DateTime.utc_now(), + latitude: 50.112198, + longitude: 11.597669 + } + ) + + assert cproc.charge_energy_added == 12.77 + assert cproc.charge_energy_used == 12.455230833333333 + assert cproc.cost == Decimal.new("7.982500") + end + + test "fees can be zero" do + car = car_fixture() + + assert %GeoFence{id: id} = + geofence_fixture(%{ + latitude: 50.1121, + longitude: 11.597, + radius: 50, + cost_per_kwh: 0.0, + session_fee: 0.0 }) assert {:ok, cproc} = diff --git a/test/teslamate_web/live/geofence_live_test.exs b/test/teslamate_web/live/geofence_live_test.exs index 0690cda5..18eac43d 100644 --- a/test/teslamate_web/live/geofence_live_test.exs +++ b/test/teslamate_web/live/geofence_live_test.exs @@ -199,7 +199,8 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do longitude: nil, latitude: nil, radius: "", - cost_per_kwh: "wat" + cost_per_kwh: "wat", + session_fee: "wat" } }) |> Floki.parse_document!() @@ -209,11 +210,13 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do assert [""] = html |> Floki.find("#geo_fence_longitude") |> Floki.attribute("value") assert [""] = html |> Floki.find("#geo_fence_radius") |> Floki.attribute("value") assert ["wat"] = html |> Floki.find("#geo_fence_cost_per_kwh") |> Floki.attribute("value") + assert ["wat"] = html |> Floki.find("#geo_fence_session_fee") |> Floki.attribute("value") assert [ field_position, field_name, field_cost_per_kwh, + field_session_fee, field_sleep_mode, _ ] = Floki.find(html, ".field.is-horizontal") @@ -228,6 +231,11 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do |> Floki.find("span") |> Floki.text() + assert "is invalid" = + field_session_fee + |> Floki.find("span") + |> Floki.text() + assert ["checked"] = field_sleep_mode |> Floki.find("#sleep_mode_#{car_id}") @@ -240,7 +248,8 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do longitude: "wot", latitude: "wat", radius: "40", - cost_per_kwh: 0.25 + cost_per_kwh: 0.25, + session_fee: 4.79 } }) |> Floki.parse_document!() @@ -250,11 +259,13 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do assert ["wot"] = html |> Floki.find("#geo_fence_longitude") |> Floki.attribute("value") assert ["40.0"] = html |> Floki.find("#geo_fence_radius") |> Floki.attribute("value") assert ["0.25"] = html |> Floki.find("#geo_fence_cost_per_kwh") |> Floki.attribute("value") + assert ["4.79"] = html |> Floki.find("#geo_fence_session_fee") |> Floki.attribute("value") assert [ field_position, field_name, field_cost_per_kwh, + field_session_fee, _field_sleep_mode, _ ] = Floki.find(html, ".field.is-horizontal") @@ -271,6 +282,11 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do field_cost_per_kwh |> Floki.find("span") |> Floki.text() + + assert "" = + field_session_fee + |> Floki.find("span") + |> Floki.text() end test "creates a new geo-fence", %{conn: conn} do