-
-
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
Tax Totals with Rates by Producer Report #10175
Tax Totals with Rates by Producer Report #10175
Conversation
193a13f
to
0b4590b
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.
Can you add a spec which covers this new report?
Otherwise the code looks fine. A bit confusing but that's due to the design of the reports.
module Reporting | ||
module Reports | ||
module SalesTax | ||
class SalesTaxTotals < Base |
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.
It looks like we should make this class shorter. Otherwise we should add it to the rubocop todo list so that other devs can use rubocop without seeing known issue they didn't cause.
0b4590b
to
a5313ca
Compare
I suggest trying to load the subreport filtering partial (if it's implemented). I don't like = render partial: "admin/reports/filters/#{@report_subtype}", locals: { f: f } rescue nil Is it better to add an instance variable to the report to tell if the subreport has additional filtering options?
If we use the same example from the discussion: Is it ok to show both? |
3dbce64
to
a1f2f80
Compare
I'm thinking what the best way to test the report. I suggest system tests with some scenarios. I started with the simplest scenario where we have:
Do you think that system tests are enough? |
I would say it would be good to have system tests with more complex scenarios for this report. @filipefurtad0 might have some suggestions :) |
20f3527
to
ddce90d
Compare
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Show resolved
Hide resolved
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Show resolved
Hide resolved
10f055a
to
deacf3d
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.
In addition to the comments I have some questions:
I'm not sure but should this report be accessible only to superadmin? Or should it be accessible when logged in as distributors/suppliers as well?
There are some acceptance criteria which we might need to cover for in request specs, especially that the data is retrievable through API. Should this work through API v1 or v0?
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Show resolved
Hide resolved
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Outdated
Show resolved
Hide resolved
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Outdated
Show resolved
Hide resolved
spec/system/admin/reports/sales_tax/sales_tax_totals_by_producer_spec.rb
Outdated
Show resolved
Hide resolved
deacf3d
to
2d6e9e3
Compare
I don't know. Maybe @lin-d-hop can answer those questions? |
2d6e9e3
to
4729125
Compare
@mkllnk query 1 returns the ideal result. # query 1 => returns 2 rows
Spree::LineItem.where(id: 9)
.order("supplier.name", "product.name", "variant.display_name")
.left_joins(variant:[product: [:supplier,{tax_category: :tax_rates}]])
# query 2 (similar to the one used in the report) => returns 1 row !!
Spree::LineItem.where(id: 9)
.includes(variant: [product: :supplier]).references(:line_items)
.order("supplier.name", "product.name", "variant.display_name")
.left_joins(variant:[product: [:supplier,{tax_category: :tax_rates}]])
# query 3 => returns 1 row
Spree::LineItem.where(id: 9)
.includes(variant: [product: :supplier]).references(:line_items)
.order("supplier.name", "product.name", "variant.display_name")
.joins('left outer join spree_tax_categories category on category.deleted_at is null and category.id = product.tax_category_id')
.joins('left outer join spree_tax_rates tax_rate on tax_rate.deleted_at is null and tax_rate.tax_category_id = category.id') If you compare |
Is Rails reducing two rows to one or is If Rails can't do it then maybe we have to let the join go. |
when I run the query directly in the database, I get 2 rows. If I add Spree::LineItem.where(id: 9)
.includes(variant: [product: :supplier]).references(:line_items)
.order("supplier.name", "product.name", "variant.display_name")
.joins('left outer join spree_tax_categories category on category.deleted_at is null and category.id = product.tax_category_id')
.joins('left outer join spree_tax_rates tax_rate on tax_rate.deleted_at is null and tax_rate.tax_category_id = category.id')
.pluck(:id)
=> [9, 9] |
I removed the SQL join query and tried to simplify the previous code used to group the line items. |
f2c6d4c
to
19df15d
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. Let's move forward with this.
private | ||
|
||
attr_reader :current_user | ||
|
||
def permissions | ||
@permissions ||= OpenFoodNetwork::Permissions.new(current_user) | ||
end | ||
|
||
def visible_order_customer_ids | ||
Permissions::Order.new(current_user).visible_orders.pluck(:customer_id) |
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.
Why did you choose pluck
over select
here?
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.
because pluck
is faster than select
, it doesn't create an active record instance.
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.
Oh, I thought it's used within another query and therefore just a sub-query within the database instead of going though Rails.
Hey @abdellani , I've tested this PR for an instance/server with added- (left) and included-taxes (right). I've overlapped the respective invoices. The (preliminary) results for 1 order only are shown below: The main reason is: accessing this report broke the page very frequently (error 504). Even when:
I've checked different browsers (sessions, and after deleting cookies). But observed timeouts nonetheless. I wonder if we should release this with a feature toggle.
Aside from the performance concerns, this looks good to go 👍 |
Ok, I've just ran an unrelated report in I'd say we're good to merge @abdellani 👍 |
Is the Background report feature activated? Could this be causing the timeouts? |
Thanks @sigmundpetersen - deactivating it seems to prevent timouts in master indeed 👍 I'll stage this PR again and double-check for timeouts (without this feature toggle on). |
Yup, I can confirm that after enabling If I run the report as an I was only able to blow things up 💥 as superadmin, and by running the report without any filters or date restrictions - I think this is acceptable. If filters or date restrictions are added then the report renders as expected 👍 Merging - thanks @abdellani! |
What? Why?
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