1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00

Fix budget money formatting (#1626)
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions

This commit is contained in:
Zach Gollwitzer 2025-01-16 19:05:34 -05:00 committed by GitHub
parent 1ae4b4d612
commit ca8bdb6241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 13 additions and 13 deletions

View file

@ -10,7 +10,7 @@ class Budget < ApplicationRecord
monetize :budgeted_spending, :expected_income, :allocated_spending, monetize :budgeted_spending, :expected_income, :allocated_spending,
:actual_spending, :available_to_spend, :available_to_allocate, :actual_spending, :available_to_spend, :available_to_allocate,
:estimated_spending, :estimated_income, :actual_income :estimated_spending, :estimated_income, :actual_income, :remaining_expected_income
class << self class << self
def for_date(date) def for_date(date)
@ -19,12 +19,13 @@ class Budget < ApplicationRecord
def find_or_bootstrap(family, date: Date.current) def find_or_bootstrap(family, date: Date.current)
Budget.transaction do Budget.transaction do
budget = Budget.find_or_create_by( budget = Budget.find_or_create_by!(
family: family, family: family,
start_date: date.beginning_of_month, start_date: date.beginning_of_month,
end_date: date.end_of_month, end_date: date.end_of_month
currency: family.currency ) do |b|
) b.currency = family.currency
end
budget.sync_budget_categories budget.sync_budget_categories

View file

@ -8,7 +8,7 @@
<div class="text-sm mr-3"> <div class="text-sm mr-3">
<p class="text-gray-900 font-medium mb-0.5"><%= budget_category.category.name %></p> <p class="text-gray-900 font-medium mb-0.5"><%= budget_category.category.name %></p>
<p class="text-gray-500"><%= format_money(budget_category.category.avg_monthly_total, precision: 0) %>/m average</p> <p class="text-gray-500"><%= format_money(Money.new(budget_category.category.avg_monthly_total, budget_category.currency), precision: 0) %>/m average</p>
</div> </div>
<div class="ml-auto"> <div class="ml-auto">

View file

@ -7,14 +7,14 @@
<div class="text-sm mr-3"> <div class="text-sm mr-3">
<p class="text-gray-900 font-medium mb-0.5"><%= budget_category.category.name %></p> <p class="text-gray-900 font-medium mb-0.5"><%= budget_category.category.name %></p>
<p class="text-gray-500"><%= format_money(budget_category.category.avg_monthly_total, precision: 0) %>/m average</p> <p class="text-gray-500"><%= format_money(Money.new(budget_category.category.avg_monthly_total, budget_category.category.family.currency), precision: 0) %>/m average</p>
</div> </div>
<div class="ml-auto"> <div class="ml-auto">
<div class="form-field w-[120px]"> <div class="form-field w-[120px]">
<div class="flex items-center"> <div class="flex items-center">
<span class="text-gray-400 text-sm mr-2">$</span> <span class="text-gray-400 text-sm mr-2">$</span>
<%= text_field_tag :uncategorized, budget_category.budgeted_spending, autocomplete: "off", class: "form-field__input text-right [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none", disabled: true %> <%= text_field_tag :uncategorized, budget_category.budgeted_spending_money, autocomplete: "off", class: "form-field__input text-right [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none", disabled: true %>
</div> </div>
</div> </div>
</div> </div>

View file

@ -9,7 +9,7 @@
</div> </div>
<div class="text-3xl font-medium <%= budget.available_to_spend.negative? ? "text-red-500" : "text-gray-900" %>"> <div class="text-3xl font-medium <%= budget.available_to_spend.negative? ? "text-red-500" : "text-gray-900" %>">
<%= format_money(budget.actual_spending) %> <%= format_money(budget.actual_spending_money) %>
</div> </div>
<%= link_to edit_budget_path(budget), class: "btn btn--secondary flex items-center gap-1 mt-2" do %> <%= link_to edit_budget_path(budget), class: "btn btn--secondary flex items-center gap-1 mt-2" do %>

View file

@ -22,9 +22,9 @@
<p class="text-gray-500"><%= format_money(budget.actual_income_money) %> earned</p> <p class="text-gray-500"><%= format_money(budget.actual_income_money) %> earned</p>
<p class="font-medium"> <p class="font-medium">
<% if budget.remaining_expected_income.negative? %> <% if budget.remaining_expected_income.negative? %>
<span class="text-green-500"><%= format_money(budget.remaining_expected_income.abs) %> over</span> <span class="text-green-500"><%= format_money(budget.remaining_expected_income_money.abs) %> over</span>
<% else %> <% else %>
<span class="text-gray-900"><%= format_money(budget.remaining_expected_income) %> left</span> <span class="text-gray-900"><%= format_money(budget.remaining_expected_income_money) %> left</span>
<% end %> <% end %>
</p> </p>
</div> </div>

View file

@ -12,8 +12,7 @@
<%= form.fields_for :family do |family_form| %> <%= form.fields_for :family do |family_form| %>
<%= family_form.select :currency, <%= family_form.select :currency,
currencies_for_select.map { |currency| [ "#{currency.name} (#{currency.iso_code})", currency.iso_code ] }, currencies_for_select.map { |currency| [ "#{currency.name} (#{currency.iso_code})", currency.iso_code ] },
{ label: t(".currency") }, { label: t(".currency") }, disabled: true %>
{ data: { auto_submit_form_target: "auto" } } %>
<%= family_form.select :locale, <%= family_form.select :locale,
language_options, language_options,