-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
sales tax totals by order report #10247
sales tax totals by order report #10247
Conversation
04272de
to
051f54a
Compare
b2cc5a9
to
939ff80
Compare
I implemented the following tests: Test 1Tax type: added
Test 2same as test 1, except that the tax is included
Test 3I added another order with variant = 200$ from another customer.
Test 4I filter customer 1 from test 3 Test 5I filter customer 2 from test 3 Test 6I filter customers 1&2 from test 3 @filipefurtad0 are those enough? or do you have any suggestions? |
The main challenge that I faced was to trigger the tax calculation after adding manually the shipping address and the enterprise fees to the order. openfoodnetwork/app/models/spree/order.rb Lines 620 to 622 in ee70645
I fixed the problem by destroying the openfoodnetwork/app/services/order_fees_handler.rb Lines 3 to 10 in ee70645
can be replaced with attr_reader :order
delegate :order_cycle,:distributor, to: :order
def initialize(order)
@order = order
end |
939ff80
to
fd3abb8
Compare
These sound great already. I think in addition, it would be great to assure different roles (superadmin, enterprise, supplier) have access to the report data. I think it would be enough to test it at the controller/request level - this is currently done here, for other reports. However, and similarly to what we've agreed before, we should not block the PR, and we can address this separately. Other than this one, no further suggestions from my side. |
0e956b5
to
c89c65c
Compare
I added new tests to try accessing the report as an admin, a distributor, and a supplier. When I use the supplier account, the controller redirects the request (status:302) instead of generating the report. The following test confirms the tax reports are not relevant to producers openfoodnetwork/spec/controllers/admin/reports_controller_spec.rb Lines 155 to 167 in ee70645
Can you please confirm? |
Many thanks @abdellani for adding the tests to the controller spec - I think this is really useful. Good point: so far we keep tax reports not accessible for OC suppliers. But since this is a new report I'm not entirely sure. I'll leave @lin-d-hop to confirm this one, as we've discussed otherwise here - but I might have misunderstood. |
These reports are only relevant to people with shops - sells = true. |
d2fabcd
to
9a22656
Compare
report_line_items.list.group_by do |line_item| | ||
[ | ||
line_item.tax_rates.map(&:id), | ||
line_item.supplier_id, | ||
line_item.order_id, | ||
] | ||
end.flat_map do |k, v| | ||
k.first.map do |tax_rate_id| | ||
{ | ||
[tax_rate_id] + k[1..] => v | ||
} | ||
end | ||
end | ||
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 have to admit I'm not able to follow this one. Maybe it's because it's the end of my day.
I can't see much mention of suppliers in the issue, PR or this example.
From what I can understand, this grouping is an extra level of grouping that occurs before the grouping defined in rules
. Is this defined here because it was too complex for that section?
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, that's correct.
Every item returned by query_result
will:
- match one row in the final report that you'll see on the HTML page (if we don't count the summary rows)
- be sent to the functions written on
columns
.
An item will look like
{
[tax_rate_id, supplier_id, order_id] => order
}
I needed that extra level of grouping because one order can much multiple :
- tax rates.
- supplier
when one of the columns' functions is called, we need to know which of the tax rates is targeted in the report row. This can only be determined from the first hash key.
Now that I think about it again, I can simplify the code by grouping the order instead of line items.
Hi @abdellani , I tried to review this but ran out of time and am having trouble understanding. I've asked one question (above) to get started, but perhaps it would be good to get somebody else's review in the meantime. By the way, what's a good way to learn more about the reports framework? Is there a tutorial or reference anywhere? |
Unfortunately no. I learned about it by solving the issues on the #9981 I was thinking about writing some documents (something that's not official, just in my personal blog :) ) that detail some parts of the system that are not documented. |
9a22656
to
db89761
Compare
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.
Great job, this looked like a tricky report to pull together!
I've added a few comments mainly just to share my thoughts and learnings.
But I also have a couple of suggestions for method naming, marked with ±
.
Otherwise all looks good to me!
spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb
Outdated
Show resolved
Hide resolved
spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb
Outdated
Show resolved
Hide resolved
ea6910a
to
def4958
Compare
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.
Great.
Hey @abdellani , I'll basically try to cover scenarios not covered in the spec. Access rights Superadmin - should access 🟢 Report output For an order with applied:
we get the report: This looks good. We can see all the fee types and associated tax. Q1: ordering of the results - should we introduce any type of ordering, in the output? It seems to me that the ordering is random, or not following an evident pattern. I'd expect completion date, but I'm not sure if this would be useful. Filters Q2: I think the customer filter is not working... Should we address this or release as is? The results above were obtained by applying the filters: However, if we add the customers filter, then no results are returned: Q3: I'm not sure what is the expected behavior when we filter by producer; Should get the orders with products supplied by a given producer, right? If so, then I think we're good. In a way I was expecting to see the tax charged by a given supplier, when filtering by Producer (supplier). For example the VAT tax above, concerns Shipping and a Product from a supplier to that OC (notice the Tax Category on the product below): I'm not entirely sure here. Summary From the three issues above: Requesting your feedback here @abdellani 🙏 |
Edit: regarding Q2 I think I've found out the issue: I think this relates to how customers are scoped on that filter. There are several options for the same email address, so it's not possible to get all the orders for a given customer, by choosing one -> so, if we select all options with the same address then the filter works, and all the results for that address are returned. |
This seems to occur in all the new reports, I'm not entirely sure we should release it as is, as the first impression for the user is that the filter does not work (-> impacting support teams, maybe) What do you think @abdellani @openfoodfoundation/train-drivers-product-owners ? |
As I'm not really accross this work in detail yet, I will let @lin-d-hop answer 👍 |
Q1: A random ordering will cause questions from users. Q2: Customer is a new filtering in this report and an important one for wholesale usage. The current implementation, from Filipes comments, appears too unintuitive to be useable. I would say we have 2 options:
|
Q1: The problem is that I'm using orders = report_line_items.list.map(&:order).uniq This is why the orders are sorted differently from what you can see on the other reports. Sorting the orders from the ruby code will be easy and I don't think this will make a big difference in the performance. Q2: The second option is better since the issue is related to multiple reports. Q3: if the supplier filter is used, the report will load orders with at least one line item produced by the selected supplier. What's next on this PR? I'll fix Q1. |
a38402c
to
dda61d1
Compare
I double-checked the report, the rows are already sorted. On the openfoodnetwork/lib/reporting/report_rows_builder.rb Lines 102 to 112 in 10d8e80
In the report, it'll be
I found the same result on my local database. Is that Ok? or do we need to sort them by customer's last name? I added |
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.
That looks good to me. This needs a new issue written up then. @abdellani You are probably the most knowledgable to write such an issue. Are you up for that?
Ah, indeed - great, thanks for pointing this out @abdellani . I was able to verify this behavior, if I disregard some exceptions which I believe are related with some non-consistent orders/data in staging. For example, this order And for that reason it appears at the top: This an edge case which needs separate investigation. However, the rest of the ordering is consistent with what you describe.
Perfect, let's tackle it separately Merging now!! 🎉 💪 |
thank you for the feedback:pray: group_key.is_a?(String) ? group_key.downcase : group_key.to_s |
@mkllnk the issue is already reported by @filipefurtad0 |
What? Why?
Need to merge this first Tax Totals with Rates by Producer Report #10175
What should we test?
Release notes
Changelog Category: User facing changes
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates