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

Conversation

Matt-Yorkley
Copy link
Contributor

@Matt-Yorkley Matt-Yorkley commented Apr 7, 2021

What? Why?

Closes #7333. See notes in issue.

What should we test?

Payment reports should load without error

Release notes

Fixed outstanding balance sum in payment report

Changelog Category: User facing changes

@Matt-Yorkley Matt-Yorkley self-assigned this Apr 7, 2021
@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #7334 (2b5acaf) into master (1ce3103) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 2b5acaf differs from pull request most recent head 05b8b8e. Consider uploading reports for the commit 05b8b8e to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7334   +/-   ##
=======================================
  Coverage   89.70%   89.70%           
=======================================
  Files         649      649           
  Lines       18865    18865           
=======================================
  Hits        16923    16923           
  Misses       1942     1942           
Impacted Files Coverage Δ
lib/open_food_network/payments_report.rb 78.20% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ce3103...05b8b8e. Read the comment docs.

@filipefurtad0 filipefurtad0 self-assigned this Apr 7, 2021
@filipefurtad0 filipefurtad0 added pr-staged-uk staging.openfoodnetwork.org.uk pr-staged-es labels Apr 7, 2021
@filipefurtad0
Copy link
Contributor

Thanks so much for the quick fix on this @Matt-Yorkley 👍

The reports responsible for the two bugsnag errors (and snails) are rendering now, after this PR. I figured it might be useful to test this under two scenarios, in which customer balances feature is toggled on and off. Found no difference whatsoever in the outcome:

  • under /admin/reports/payments

Itemized totals:

image

Payment totals:

image

Notice the strangely long decimal. Looks a bit weird - I'm guessing they were the root cause? I've seen this recently... (under products somehow...?)

Placed an order and checked that the customer balance is updated. The weird looking zeroes disappear if one selects "all" from the dropdown, and re-appear if a hub is selected:

Peek 2021-04-07 12-19

Peek 2021-04-07 12-18

I'm not sure this is related. Just felt it's worth pointing out since the Bugsnag does mention BigDecimals

It's ready to go.

@filipefurtad0 filipefurtad0 removed pr-staged-es pr-staged-uk staging.openfoodnetwork.org.uk labels Apr 7, 2021
@Matt-Yorkley Matt-Yorkley merged commit 52c7abf into openfoodfoundation:master Apr 7, 2021
@@ -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.

@filipefurtad0
Copy link
Contributor

Notice the strangely long decimal. Looks a bit weird - I'm guessing they were the root cause? I've seen this recently... (under products somehow...?)

Just met this again (for the record, unit_prices is off):

Peek 2021-04-21 21-38

This value gets actually gets stored and is even displayed in the shopfront:

image

I wonder if this can mess anything throughout the app...

@sauloperez
Copy link
Contributor

sauloperez commented Apr 28, 2021

This definitely needs an issue. We're missing rounding somewhere.

@filipefurtad0
Copy link
Contributor

filipefurtad0 commented Apr 28, 2021

Thanks @sauloperez , opened #7504.

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.

Payment reports broken
3 participants