-
-
Notifications
You must be signed in to change notification settings - Fork 792
Add Balance Due and Available Credit columns to Customers report #14390
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
Open
NiftyGaloot
wants to merge
6
commits into
openfoodfoundation:master
Choose a base branch
from
NiftyGaloot:wishlist-562-balance-credit-columns
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−10
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9733a5
Fix balance_due and credit_due columns per review feedback
NiftyGaloot d520d69
Add Balance Due and Available Credit columns to Customers report
NiftyGaloot 1d5370d
Fix indentation regression and add credit_due spec coverage
NiftyGaloot 51fec33
Fix E2E spec to not rely on seed data for non-zero column assertions
NiftyGaloot 7865af9
Remove Playwright E2E test — not part of OFN test suite
NiftyGaloot ca9368c
Suppress CyclomaticComplexity cop on columns method
NiftyGaloot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ def query_result | |
| end.values | ||
| end | ||
|
|
||
| # rubocop:disable Metrics/AbcSize | ||
| # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude is correct in its assessment but the intent of the comment is to say we are not going to fix it. Surprisingly, rubocop is not complaining after removal, so happy to keep as it is. |
||
| def columns | ||
| { | ||
| first_name: proc { |orders| last_completed_order(orders).billing_address.firstname }, | ||
|
|
@@ -35,9 +35,29 @@ def columns | |
| total_orders: proc { |orders| orders.count }, | ||
| total_incl_tax: proc { |orders| orders.map(&:total).compact.sum }, | ||
| last_completed_order_date: proc { |orders| last_completed_order_date(orders) }, | ||
| # Outstanding amount the customer still owes across all their orders at this hub. | ||
| # Uses outstanding_balance (which deducts incomplete customer credit payments) rather | ||
| # than the raw order total, so applied-but-not-yet-captured credits are accounted for. | ||
| # Floored at zero — negative values mean the shop owes the customer, which is | ||
| # captured separately in credit_due. | ||
| balance_due: proc { |orders| | ||
| total = orders.sum { |o| o.outstanding_balance.to_f } | ||
| total.positive? ? total : 0 | ||
| }, | ||
| # Credit held in the customer's account (from CustomerAccountTransaction records), | ||
| # available to be applied to future orders. This is a separate ledger from order | ||
| # balances — credit is granted explicitly (e.g. via the bulk credit admin action) | ||
| # and does not simply reflect overpayments on individual orders. | ||
| credit_due: proc { |orders| | ||
| orders.first.customer&.credit_balance || 0 | ||
| }, | ||
| } | ||
| end | ||
| # rubocop:enable Metrics/AbcSize | ||
| # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
|
|
||
| def columns_format | ||
| { balance_due: :currency, credit_due: :currency } | ||
| end | ||
|
|
||
| def filter(orders) | ||
| filter_to_completed_at filter_to_distributor filter_to_order_cycle orders | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks for documenting the divergence. It's out of scope for this PR, but it would be good to get others point on vue on this.
OutstandingBalanceQuerytakes into account any existing order, ie it includes non placed orders. This doesn't really make sense to me, if the order is not placed then the balance is not technically outstanding ? If we fix the query to only includes placed order, then the divergence will go away. @mkllnk @dacook what do you think ?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.
Thanks for looking into this, yes what you say makes sense.
So in other words, there's a (now known) bug in the admin customers page, and the above describes how to fix it. Seems like a good first issue.
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.
This bug sounds related, but might be more complicated.. 😳 #6038
Without investigating further, I would probably just add the above comment to that issue for future reference... unless Gaetan you see a better way?