-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto naming of Transfer Transaction #1393
Conversation
app/models/account/entry.rb
Outdated
|
||
def assign_transfer_name | ||
self.name = transfer.name | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this logic directly to the transfers controller:
name: transfer_params[:name] |
Furthermore, it may be a nice touch if we had generated names for each of the entries within the transfer:
maybe/app/models/account/transfer.rb
Lines 46 to 64 in 490f445
def build_from_accounts(from_account, to_account, date:, amount:, currency:, name:) | |
outflow = from_account.entries.build \ | |
amount: amount.abs, | |
currency: from_account.currency, | |
date: date, | |
name: name, | |
marked_as_transfer: true, | |
entryable: Account::Transaction.new | |
inflow = to_account.entries.build \ | |
amount: amount.abs * -1, | |
currency: from_account.currency, | |
date: date, | |
name: name, | |
marked_as_transfer: true, | |
entryable: Account::Transaction.new | |
new entries: [ outflow, inflow ] | |
end |
For example, the "from" name could be something like "Transfer to #{to_account.name}"
and the "to" name could be "Transfer from #{from_account.name}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , This makes sense.
I believe if we’re assigning distinct names to both entries, then the name
parameter in build_from_accounts
function would be of no use, so removing it seems like the right approach to me
Also, Are we going to store the full name i.e Transfer from {from account} to {to account} elsewhere or this will going to be generated at runtime, like we do now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I've noticed that locales are already used in the project, so directly adding "Transfer to #{to_account.name}"
might not be ideal. Would it be better to create a locale attribute under the entry
folder in en.yml
, or would that be overkill for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Harry-kp regarding locales, we're going to have to go back through a lot of the model stuff and make bulk updates once we start down the path of #1225 , so for this change, let's just hardcode it for now.
And in regards to the name:
param, fully agree.
Are we going to store the full name i.e Transfer from {from account} to {to account} elsewhere
That's my bad, I forgot that Transfer
does not have a stored name
field. We can just keep generating at runtime as we're doing now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zachgoll Changes are done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looks great!
Why?
What?
Transfer from {from_account} to {to_account}
.Earlier it was saved asTransfer from Originator to Receiver
or whatever user inputs in the Transfer form.Probable Concerns
Screen.Recording.2024-10-30.at.4.29.50.PM.mov