display cpr for ammo packs and add original count for ammo packs

This commit is contained in:
shibao 2022-11-12 14:33:11 -05:00
parent 3480aff61d
commit 1fed895b82
18 changed files with 349 additions and 94 deletions

View File

@ -4,6 +4,8 @@
- Fix whitespace when copying invite url
- Make ammo type show page also display ammo groups as table
- Make container show page also display ammo groups as table
- Display CPR for ammo packs
- Add original count for ammo packs
# v0.6.0
- Update translations

View File

@ -513,6 +513,28 @@ defmodule Cannery.Ammo do
round(count / (count + shot_group_sum) * 100)
end
@doc """
Gets the original count for an ammo group
"""
@spec get_original_count(AmmoGroup.t()) :: non_neg_integer()
def get_original_count(%AmmoGroup{count: count} = ammo_group) do
count + get_used_count(ammo_group)
end
@doc """
Calculates the CPR for a single ammo group
"""
@spec get_cpr(AmmoGroup.t()) :: nil | float()
def get_cpr(%AmmoGroup{price_paid: nil}), do: nil
def get_cpr(%AmmoGroup{price_paid: price_paid} = ammo_group),
do: calculate_cpr(price_paid, get_original_count(ammo_group))
@spec calculate_cpr(price_paid :: float() | nil, count :: integer()) :: float() | nil
defp calculate_cpr(nil, _count), do: nil
defp calculate_cpr(_price_paid, 0), do: nil
defp calculate_cpr(price_paid, total_count), do: price_paid / total_count
@doc """
Creates multiple ammo_groups at once.

View File

@ -17,6 +17,7 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
preloads = if show_container, do: [:ammo_type, :container], else: [:ammo_type]
ammo_group = ammo_group |> Repo.preload(preloads)
assigns = assigns |> assign(:ammo_group, ammo_group)
~H"""
@ -38,6 +39,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<%= if @ammo_group.count == 0, do: gettext("Empty"), else: @ammo_group.count %>
</span>
<%= if @ammo_group |> Ammo.get_original_count() != @ammo_group.count do %>
<span class="rounded-lg title text-lg">
<%= gettext("Original Count:") %>
<%= @ammo_group |> Ammo.get_original_count() %>
</span>
<% end %>
<%= if @ammo_group.notes do %>
<span class="rounded-lg title text-lg">
<%= gettext("Notes:") %>
@ -64,6 +72,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
amount: @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)
) %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("CPR:") %>
<%= gettext("$%{amount}",
amount: @ammo_group |> Ammo.get_cpr() |> :erlang.float_to_binary(decimals: 2)
) %>
</span>
<% end %>
<%= if @show_container and @ammo_group.container do %>

View File

@ -82,11 +82,19 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
columns = [
%{label: gettext("Count"), key: :count},
%{label: gettext("Price paid"), key: :price_paid},
%{label: gettext("CPR"), key: :cpr},
%{label: gettext("% left"), key: :remaining},
%{label: gettext("Notes"), key: :notes}
| columns
]
columns =
if show_used do
[%{label: gettext("Original Count"), key: :original_count} | columns]
else
columns
end
columns =
if ammo_type == [] do
columns
@ -215,6 +223,18 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
"""}
end
defp get_value_for_key(:original_count, ammo_group, _additional_data),
do: ammo_group |> Ammo.get_original_count()
defp get_value_for_key(:cpr, %{price_paid: nil}, _additional_data),
do: gettext("No cost information")
defp get_value_for_key(:cpr, ammo_group, _additional_data) do
gettext("$%{amount}",
amount: ammo_group |> Ammo.get_cpr() |> :erlang.float_to_binary(decimals: 2)
)
end
defp get_value_for_key(:count, %{count: count}, _additional_data),
do: if(count == 0, do: gettext("Empty"), else: count)

View File

@ -11,7 +11,7 @@
<span class="rounded-lg title text-lg">
<%= gettext("Original count:") %>
<%= @ammo_group.count + Ammo.get_used_count(@ammo_group) %>
<%= Ammo.get_original_count(@ammo_group) %>
</span>
<span class="rounded-lg title text-lg">

View File

@ -52,7 +52,7 @@ msgstr "Admins:"
msgid "Ammo"
msgstr "Munition"
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -131,7 +131,7 @@ msgstr "Korrosiv"
msgid "Count"
msgstr "Anzahl"
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -322,7 +322,7 @@ msgid "No tags"
msgstr "Keine Tags"
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -331,7 +331,7 @@ msgstr "Keine Tags"
msgid "Notes"
msgstr "Bemerkungen"
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -354,7 +354,7 @@ msgstr "Druck"
msgid "Price paid"
msgstr "Kaufpreis"
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr "Kaufpreis:"
@ -573,8 +573,10 @@ msgstr "Kein weiterer Behälter"
msgid "Shot log"
msgstr "Schießkladde"
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -679,13 +681,14 @@ msgstr "Editiere %{name} Tags"
msgid "Rounds:"
msgstr "Patronen:"
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr "Keine Preisinformationen"
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr "% verbleibend"
@ -761,7 +764,7 @@ msgstr "Munitionsart"
msgid "Added on"
msgstr "Hinzugefügt am"
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -870,7 +873,7 @@ msgstr ""
msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "Container:"
msgstr "Behälter"
@ -888,12 +891,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1079,8 +1082,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr "%{name} bearbeiten"
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count"
msgstr "Ursprüngliche Anzahl:"
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count:"
msgstr "Ursprüngliche Anzahl:"

View File

@ -187,7 +187,7 @@ msgstr ""
"Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War "
"%{multiplier}"
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

@ -37,7 +37,7 @@ msgstr ""
msgid "Ammo"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -116,7 +116,7 @@ msgstr ""
msgid "Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -307,7 +307,7 @@ msgid "No tags"
msgstr ""
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -316,7 +316,7 @@ msgstr ""
msgid "Notes"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -339,7 +339,7 @@ msgstr ""
msgid "Price paid"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr ""
@ -556,8 +556,10 @@ msgstr ""
msgid "Shot log"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -662,13 +664,14 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr ""
@ -744,7 +747,7 @@ msgstr ""
msgid "Added on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -853,7 +856,7 @@ msgstr ""
msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format
msgid "Container:"
msgstr ""
@ -871,12 +874,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1062,8 +1065,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format
msgid "Original Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format
msgid "Original Count:"
msgstr ""

View File

@ -38,7 +38,7 @@ msgstr ""
msgid "Ammo"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -117,7 +117,7 @@ msgstr ""
msgid "Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -308,7 +308,7 @@ msgid "No tags"
msgstr ""
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -317,7 +317,7 @@ msgstr ""
msgid "Notes"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -340,7 +340,7 @@ msgstr ""
msgid "Price paid"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr ""
@ -557,8 +557,10 @@ msgstr ""
msgid "Shot log"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -663,13 +665,14 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr ""
@ -745,7 +748,7 @@ msgstr ""
msgid "Added on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -854,7 +857,7 @@ msgstr ""
msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "Container:"
msgstr ""
@ -872,12 +875,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1063,8 +1066,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count:"
msgstr ""

View File

@ -170,7 +170,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr ""
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

@ -169,7 +169,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr ""
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

@ -52,7 +52,7 @@ msgstr ""
msgid "Ammo"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -131,7 +131,7 @@ msgstr ""
msgid "Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -322,7 +322,7 @@ msgid "No tags"
msgstr ""
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -331,7 +331,7 @@ msgstr ""
msgid "Notes"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -354,7 +354,7 @@ msgstr ""
msgid "Price paid"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr ""
@ -571,8 +571,10 @@ msgstr ""
msgid "Shot log"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -677,13 +679,14 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr ""
@ -759,7 +762,7 @@ msgstr ""
msgid "Added on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -868,7 +871,7 @@ msgstr ""
msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "Container:"
msgstr ""
@ -886,12 +889,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1077,8 +1080,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count:"
msgstr ""

View File

@ -185,7 +185,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr ""
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

@ -52,7 +52,7 @@ msgstr "Administrateur·ices:"
msgid "Ammo"
msgstr "Munition"
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -131,7 +131,7 @@ msgstr "Corrosive"
msgid "Count"
msgstr "Quantité"
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -322,7 +322,7 @@ msgid "No tags"
msgstr "Aucun tag"
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -331,7 +331,7 @@ msgstr "Aucun tag"
msgid "Notes"
msgstr "Notes"
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -354,7 +354,7 @@ msgstr "Pression"
msgid "Price paid"
msgstr "Prix payé"
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr "Prix payé:"
@ -575,8 +575,10 @@ msgstr "Aucun autre conteneur"
msgid "Shot log"
msgstr "Évènements de tir"
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -681,13 +683,14 @@ msgstr "Éditer les tags de %{name}"
msgid "Rounds:"
msgstr "Cartouches:"
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr "Aucune information de prix"
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr "%restante"
@ -763,7 +766,7 @@ msgstr "Types de munition"
msgid "Added on"
msgstr "Ajouté le"
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -873,7 +876,7 @@ msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
"Laissez \"Utilisations restantes\" vide pour rendre l'invitation illimitée"
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format, fuzzy
msgid "Container:"
msgstr "Conteneur"
@ -891,12 +894,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1082,8 +1085,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr "Éditer %{name}"
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count"
msgstr "Nombre original:"
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count:"
msgstr "Nombre original:"

View File

@ -186,7 +186,7 @@ msgstr "Impossible d'analyser le nombre de copies"
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr "Multiplicateur invalide"

View File

@ -48,7 +48,7 @@ msgstr ""
msgid "Ammo"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:94
#: lib/cannery_web/components/ammo_group_table_component.ex:102
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:21
#, elixir-autogen, elixir-format
msgid "Ammo type"
@ -127,7 +127,7 @@ msgstr ""
msgid "Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:37
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/live/ammo_group_live/show.html.heex:8
#, elixir-autogen, elixir-format
msgid "Count:"
@ -318,7 +318,7 @@ msgid "No tags"
msgstr ""
#: lib/cannery_web/components/add_shot_group_component.html.heex:37
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#: lib/cannery_web/components/ammo_group_table_component.ex:87
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:41
#: lib/cannery_web/live/ammo_group_live/show.ex:88
#: lib/cannery_web/live/range_live/form_component.html.heex:29
@ -327,7 +327,7 @@ msgstr ""
msgid "Notes"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:43
#: lib/cannery_web/components/ammo_group_card.ex:51
#: lib/cannery_web/live/ammo_group_live/show.html.heex:24
#, elixir-autogen, elixir-format
msgid "Notes:"
@ -350,7 +350,7 @@ msgstr ""
msgid "Price paid"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:62
#: lib/cannery_web/components/ammo_group_card.ex:70
#, elixir-autogen, elixir-format
msgid "Price paid:"
msgstr ""
@ -567,8 +567,10 @@ msgstr ""
msgid "Shot log"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:63
#: lib/cannery_web/components/ammo_group_table_component.ex:157
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:78
#: lib/cannery_web/components/ammo_group_table_component.ex:165
#: lib/cannery_web/components/ammo_group_table_component.ex:233
#: lib/cannery_web/live/ammo_group_live/show.html.heex:37
#: lib/cannery_web/live/ammo_group_live/show.html.heex:44
#: lib/cannery_web/live/ammo_type_live/index.ex:179
@ -673,13 +675,14 @@ msgstr ""
msgid "Rounds:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:230
#: lib/cannery_web/live/ammo_type_live/index.ex:178
#: lib/cannery_web/live/ammo_type_live/show.html.heex:142
#, elixir-autogen, elixir-format
msgid "No cost information"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#: lib/cannery_web/components/ammo_group_table_component.ex:86
#, elixir-autogen, elixir-format
msgid "% left"
msgstr ""
@ -755,7 +758,7 @@ msgstr ""
msgid "Added on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:49
#: lib/cannery_web/components/ammo_group_card.ex:57
#: lib/cannery_web/live/ammo_group_live/show.html.heex:30
#: lib/cannery_web/live/ammo_type_live/show.html.heex:123
#, elixir-autogen, elixir-format
@ -864,7 +867,7 @@ msgstr ""
msgid "Leave \"Uses left\" blank to make invite unlimited"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:71
#: lib/cannery_web/components/ammo_group_card.ex:86
#, elixir-autogen, elixir-format
msgid "Container:"
msgstr ""
@ -882,12 +885,12 @@ msgstr ""
msgid "Used up on"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:55
#: lib/cannery_web/components/ammo_group_card.ex:63
#, elixir-autogen, elixir-format
msgid "Used up on:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:193
#: lib/cannery_web/components/ammo_group_table_component.ex:201
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
@ -1073,8 +1076,28 @@ msgstr ""
msgid "Edit %{ammo_type_name}"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:38
#: lib/cannery_web/components/ammo_group_table_component.ex:219
#: lib/cannery_web/components/ammo_group_card.ex:39
#: lib/cannery_web/components/ammo_group_table_component.ex:239
#, elixir-autogen, elixir-format
msgid "Empty"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:85
#, elixir-autogen, elixir-format
msgid "CPR"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:77
#, elixir-autogen, elixir-format
msgid "CPR:"
msgstr ""
#: lib/cannery_web/components/ammo_group_table_component.ex:93
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count"
msgstr ""
#: lib/cannery_web/components/ammo_group_card.ex:44
#, elixir-autogen, elixir-format, fuzzy
msgid "Original Count:"
msgstr ""

View File

@ -185,7 +185,7 @@ msgstr ""
msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}"
msgstr ""
#: lib/cannery/ammo.ex:587
#: lib/cannery/ammo.ex:609
#, elixir-autogen, elixir-format
msgid "Invalid multiplier"
msgstr ""

View File

@ -232,7 +232,10 @@ defmodule Cannery.AmmoTest do
current_user = user_fixture()
ammo_type = ammo_type_fixture(current_user)
container = container_fixture(current_user)
{1, [ammo_group]} = ammo_group_fixture(%{"count" => 25}, ammo_type, container, current_user)
{1, [ammo_group]} =
%{"count" => 50, "price_paid" => 36.1}
|> ammo_group_fixture(ammo_type, container, current_user)
[
ammo_type: ammo_type,
@ -424,13 +427,13 @@ defmodule Cannery.AmmoTest do
|> Ammo.get_last_used_shot_group()
end
test "get_percentage_remaining/1 gets accurate total round count for ammo type",
test "get_percentage_remaining/1 gets accurate total round count",
%{ammo_group: ammo_group, current_user: current_user} do
assert 100 = Ammo.get_percentage_remaining(ammo_group)
shot_group_fixture(%{"count" => 14}, current_user, ammo_group)
assert 44 =
assert 72 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
@ -438,11 +441,66 @@ defmodule Cannery.AmmoTest do
shot_group_fixture(%{"count" => 11}, current_user, ammo_group)
assert 50 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_percentage_remaining()
shot_group_fixture(%{"count" => 25}, current_user, ammo_group)
assert 0 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_percentage_remaining()
end
test "get_cpr/1 gets accurate cpr",
%{ammo_group: ammo_group, current_user: current_user} do
assert %AmmoGroup{price_paid: nil} |> Ammo.get_cpr() |> is_nil()
assert %AmmoGroup{count: 1, price_paid: nil} |> Ammo.get_cpr() |> is_nil()
assert 1.0 = %AmmoGroup{count: 1, price_paid: 1.0} |> Ammo.get_cpr()
assert 1.5 = %AmmoGroup{count: 2, price_paid: 3.0} |> Ammo.get_cpr()
assert 0.722 = %AmmoGroup{count: 50, price_paid: 36.1} |> Ammo.get_cpr()
# with shot group, maintains total
shot_group_fixture(%{"count" => 14}, current_user, ammo_group)
assert 0.722 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_cpr()
end
test "get_original_count/1 gets accurate original count",
%{ammo_group: ammo_group, current_user: current_user} do
assert 50 = Ammo.get_original_count(ammo_group)
shot_group_fixture(%{"count" => 14}, current_user, ammo_group)
assert 50 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_original_count()
shot_group_fixture(%{"count" => 11}, current_user, ammo_group)
assert 50 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_original_count()
shot_group_fixture(%{"count" => 25}, current_user, ammo_group)
assert 50 =
ammo_group
|> Repo.reload!()
|> Repo.preload(:shot_groups, force: true)
|> Ammo.get_original_count()
end
end
end