1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Multi-currency support (#425)

* Initial foundational pass at multi-currency

* Default format currency

* More work on currency and exchanging

* Re-build currencies on change

* Currency import/setup

* Background job overhaul + cheaper OXR plan support

* Lint fixes

* Test fixes

* Multi-currency setup instructions

* Allow decimals in the balance field

* Spacing fix for form

---------

Signed-off-by: Josh Pigford <josh@joshpigford.com>
This commit is contained in:
Josh Pigford 2024-02-10 16:18:56 -06:00 committed by GitHub
parent 94f7b4ea8f
commit aa351ae616
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 634 additions and 176 deletions

View file

@ -2,13 +2,13 @@
<% accounts = Current.family.accounts.where(accountable_type: type.name) %>
<% if accounts.sum(&:balance) > 0 %>
<% if accounts.sum(&:converted_balance) > 0 %>
<details class="mb-1 text-sm group">
<summary class="flex gap-4 px-2 py-3 items-center w-full rounded-[10px] font-medium hover:bg-[#f2f2f2]">
<%= lucide_icon("chevron-down", class: "hidden group-open:block text-[#737373] w-5 h-5") %>
<%= lucide_icon("chevron-right", class: "group-open:hidden text-[#737373] w-5 h-5") %>
<div class="text-left"><%= type.model_name.human %></div>
<div class="ml-auto"><%= humanized_money_with_symbol accounts.sum(&:balance) %></div>
<div class="ml-auto"><%= format_currency accounts.sum(&:converted_balance) %></div>
</summary>
<% accounts.each do |account| %>
@ -19,7 +19,7 @@
<p class="text-xs text-[#737373]"><%= account.subtype&.humanize %></p>
<% end %>
</div>
<p class="ml-auto font-medium"><%= humanized_money_with_symbol account.balance %></p>
<p class="ml-auto font-medium"><%= format_currency account.converted_balance %></p>
</div>
<% end %>

View file

@ -4,14 +4,14 @@
<% Current.family.accounts.each do |account| %>
<div class="flex flex-row items-center justify-between px-3 py-3 mb-2 bg-white shadow-sm rounded-xl">
<div class="flex w-1/3 items-center text-sm">
<div class="flex items-center w-1/3 text-sm">
<%= account.name %>
</div>
<div class="flex w-1/3 items-center text-sm">
<div class="flex items-center w-1/3 text-sm">
<%= to_accountable_title(account.accountable) %>
</div>
<p class="flex w-1/3 text-sm text-right">
<span class="block mb-1"><%= humanized_money_with_symbol account.balance %></span>
<span class="block mb-1"><%= format_currency account.converted_balance %></span>
</p>
</div>
<% end %>

View file

@ -69,16 +69,17 @@
</div>
<%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "m-5 mt-1 flex flex-col justify-between grow", data: { turbo: false } } do |f| %>
<div class="space-y-4 grow">
<%= f.hidden_field :accountable_type %>
<div class="space-y-4 grow">
<%= f.hidden_field :accountable_type %>
<%= f.text_field :name, placeholder: 'Example account name', required: 'required', label: 'Account name' %>
<%= f.text_field :name, placeholder: 'Example account name', required: 'required', label: 'Account name' %>
<%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
<%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
<%= f.number_field :balance, placeholder: number_to_currency(0), in: 0.00..100000000.00, required: 'required', label: true %>
<%= f.number_field :original_balance, step: :any, placeholder: 0.00, in: 0.00..100000000.00, required: 'required', label: true %>
<%= f.collection_select :original_currency, Currency.all, :iso_code, :iso_code, { prompt: "Choose a currency", selected: Current.family.currency }, { required: 'required', label: "Base Currency" } %>
</div>
<%= f.submit "Add #{@account.accountable.model_name.human.downcase}" %>
<% end %>
<% end %>