Skip to content
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

Add option to ignore financial transaction when calculating the balance #817

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

paroga
Copy link
Member

@paroga paroga commented Feb 8, 2021

No description provided.


def update_balance_of_ordergroups
ordergroups.each { |og| og.update_balance! }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be quite an expensive operation, I'm a little worried it may introduce problems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm too, but we have no good way to do this otherwise, and it's a VERY unusual operation, so it shouldn't matter that much

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed unusual, but I'd be reluctant to make people wary of changing the name, for example.
Actually, when/why exactly does the balance need to be changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we ignore some FinancialTransactionClass the account_balance can change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that is: on create and destroy (when ignore_for_account_balance is false), and when ignore_for_account_balance changes, right?

What about not doing this when the name changes?
We can move it to a background job if it becomes too slow in practice for someone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO getting the relevant data from the database to do a selective change is much more comlicated, than just doing it for all ordergroups. as already stated, this is something which nearly never happens and I don't see the benefit of adding complex logic for such a rare case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create would be not required, since there are no FinancialTransaction where we need to apply it.

result = Ordergroup.include_transaction_class_sum.where(id: og).first
expect(result["sum_of_class_#{ftc1.id}"]).to eq 44
expect(result["sum_of_class_#{ftc2.id}"]).to eq 400
expect(og.account_balance).to eq 400
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this separate tests, please? So that we can more easily see which parts break when modifying code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def update_balance_of_ordergroups
ordergroups.each { |og| og.update_balance! }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed unusual, but I'd be reluctant to make people wary of changing the name, for example.
Actually, when/why exactly does the balance need to be changed?


def update_balance_of_ordergroups
ordergroups.each { |og| og.update_balance! }
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this only really needs to happen when the financial_transaction_class changes - or perhaps I'm missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Maybe I fell into the pit of premature optimization :)

@paroga paroga merged commit 7d5155b into foodcoops:master Feb 17, 2021
@paroga paroga deleted the iftc branch February 17, 2021 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants