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

Fix outstanding balance sum in payment report #7334

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/open_food_network/payments_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def columns
proc { |orders| orders.first.distributor.name },
proc { |orders| orders.to_a.sum(&:item_total) },
proc { |orders| orders.sum(&:ship_total) },
proc { |orders| orders.sum(&:outstanding_balance) },
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we were just missing https://www.rubydoc.info/stdlib/bigdecimal/BigDecimal#coerce-instance_method. I didn't know this was possible 😍

I wonder if we didn't spot this due to the Ruby upgrade that after this 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's really weird. I tried 5 or 6 times to write a test for this, in feature specs, controller specs, model specs... it passed without error every time! And we actually do have a test for this already, and it was passing. Really easy to replicate in the browser or console though! 💥

#WTF 🤷‍♂️ 🤷‍♂️ 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 🤔 I was probably stubbing things I shouldn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

proc { |orders| orders.sum{ |order| order.outstanding_balance.to_f } },
proc { |orders| orders.map(&:total).sum }]
when "payment_totals"
[proc { |orders| orders.first.payment_state },
Expand All @@ -124,7 +124,7 @@ def columns
}.sum(&:amount)
}
},
proc { |orders| orders.sum(&:outstanding_balance) }]
proc { |orders| orders.sum{ |order| order.outstanding_balance.to_f } }]
else
[proc { |payments| payments.first.order.payment_state },
proc { |payments| payments.first.order.distributor.name },
Expand Down