Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

resloved issues raised by ai chatbot

Shibu Md917143fd638
diff --git a/app/views/api/v1/transfers/_transfer.json.jbuilder b/app/views/api/v1/transfers/_transfer.json.jbuilder
index 5c3ddc9b83..734d6c8636 100644
--- a/app/views/api/v1/transfers/_transfer.json.jbuilder
+++ b/app/views/api/v1/transfers/_transfer.json.jbuilder
@@ -8,9 +8,9 @@ json.amount_cents money_to_minor_units(transfer.amount_abs)
json.currency transfer.inflow_transaction.entry.currency
json.transfer_type transfer.transfer_type
json.notes transfer.notes
-json.source_fee_amount transfer.source_fee_amount.to_f
+json.source_fee_amount transfer.source_fee_amount.to_s("F")
json.source_fee_currency transfer.from_account&.currency
-json.destination_fee_amount transfer.destination_fee_amount.to_f
+json.destination_fee_amount transfer.destination_fee_amount.to_s("F")
json.destination_fee_currency transfer.to_account&.currency
json.inflow_transaction do
diff --git a/app/views/transfers/_form.html.erb b/app/views/transfers/_form.html.erb
index e80dfd2ff3..0534205760 100644
--- a/app/views/transfers/_form.html.erb
+++ b/app/views/transfers/_form.html.erb
@@ -80,14 +80,14 @@
label: t(".source_fee"),
min: 0,
placeholder: "0.00",
- step: 0.01,
+ step: "any",
data: { transfer_form_target: "sourceFee" } %>
<%= f.number_field :destination_fee_amount,
label: t(".destination_fee"),
min: 0,
placeholder: "0.00",
- step: 0.01,
+ step: "any",
data: { transfer_form_target: "destinationFee" } %>
</div>
<% end %>
diff --git a/db/migrate/20260604000000_add_fees_to_transfers.rb b/db/migrate/20260604000000_add_fees_to_transfers.rb
index ca7297971d..f22a54ee5c 100644
--- a/db/migrate/20260604000000_add_fees_to_transfers.rb
+++ b/db/migrate/20260604000000_add_fees_to_transfers.rb
@@ -2,5 +2,8 @@ class AddFeesToTransfers < ActiveRecord::Migration[7.2]
def change
add_column :transfers, :source_fee_amount, :decimal, precision: 19, scale: 4, null: false, default: 0
add_column :transfers, :destination_fee_amount, :decimal, precision: 19, scale: 4, null: false, default: 0
+
+ add_check_constraint :transfers, "source_fee_amount >= 0", name: "check_source_fee_non_negative"
+ add_check_constraint :transfers, "destination_fee_amount >= 0", name: "check_destination_fee_non_negative"
end
end
diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb
index a8dee39462..f07a96f69a 100644
--- a/spec/swagger_helper.rb
+++ b/spec/swagger_helper.rb
@@ -850,9 +850,9 @@ RSpec.configure do |config|
currency: { type: :string },
transfer_type: { type: :string, enum: %w[transfer liability_payment loan_payment] },
notes: { type: :string, nullable: true },
- source_fee_amount: { type: :number, nullable: true, description: 'Fee charged to the source account' },
+ source_fee_amount: { type: :string, nullable: true, description: 'Fee charged to the source account' },
source_fee_currency: { type: :string, nullable: true },
- destination_fee_amount: { type: :number, nullable: true, description: 'Fee deducted from the destination account' },
+ destination_fee_amount: { type: :string, nullable: true, description: 'Fee deducted from the destination account' },
destination_fee_currency: { type: :string, nullable: true },
inflow_transaction: { '$ref' => '#/components/schemas/TransferTransactionSide' },
outflow_transaction: { '$ref' => '#/components/schemas/TransferTransactionSide' },
diff --git a/test/models/transfer_test.rb b/test/models/transfer_test.rb
index f2abc4df9c..f77539f84c 100644
--- a/test/models/transfer_test.rb
+++ b/test/models/transfer_test.rb
@@ -153,7 +153,7 @@ class TransferTest < ActiveSupport::TestCase
test "transfer with both source and destination fees adjusts validation" do
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 103)
- inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -97)
+ inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -94)
transfer = Transfer.new(
inflow_transaction: inflow_entry.transaction,
diff --git a/test/support/entries_test_helper.rb b/test/support/entries_test_helper.rb
index e4f1a230f4..b7793cc42c 100644
--- a/test/support/entries_test_helper.rb
+++ b/test/support/entries_test_helper.rb
@@ -69,7 +69,7 @@ module EntriesTestHelper
from_account.entries.create!(
name: "Transfer to #{to_account.name}",
date: date,
- amount: -total_outflow,
+ amount: total_outflow,
currency: currency,
entryable: outflow_transaction
)
@@ -77,7 +77,7 @@ module EntriesTestHelper
to_account.entries.create!(
name: "Transfer from #{from_account.name}",
date: date,
- amount: net_inflow,
+ amount: -net_inflow,
currency: currency,
entryable: inflow_transaction
)