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

[SR-102] Suggestion - Change the SKU's displayed to normal products names and add hyperlinks #197

Open
wants to merge 5 commits into
base: spree-reports
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ def call
variants = by_completed_at_min(variants)
variants = by_completed_at_max(variants)

variants = variants.group('spree_variants.sku')
.select('spree_variants.sku, sum(spree_line_items.quantity * spree_prices.amount) as line_item_total')
variants = variants.group(
'spree_variants.id',

Choose a reason for hiding this comment

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

Suggested change
'spree_variants.id',
"#{Spree::Variant.table_name}.id",

please don't hardcode table names in SQL queries

'spree_variants.is_master',
'spree_variants.product_id'
)
.select(
'spree_variants.id',
'spree_variants.is_master',
'spree_variants.product_id',
'sum(spree_line_items.quantity * spree_prices.amount) as line_item_total'

Choose a reason for hiding this comment

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

@piotrleniec-spark this calculation is wrong, it doesn't include discounts or tax, this can be fetched from LineItem model

Copy link

Choose a reason for hiding this comment

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

@damianlegawiec fixed ✅

)
.order(line_item_total: :desc)

variants = by_top(variants)

variants.to_a.map { |v| [v.sku, v.line_item_total] }
variants.to_a.map { |v| [v.descriptive_name, v.line_item_total] }
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ def call
variants = by_completed_at_min(variants)
variants = by_completed_at_max(variants)

variants = variants.group('spree_variants.sku')
.select('spree_variants.sku, sum(spree_line_items.quantity) as total_quantity_sold')
variants = variants.group(
'spree_variants.id',
'spree_variants.is_master',
'spree_variants.product_id'
)
.select(
'spree_variants.id',
'spree_variants.is_master',
'spree_variants.product_id',
'sum(spree_line_items.quantity) as total_quantity_sold'
)
.order(total_quantity_sold: :desc)

variants = by_top(variants)

variants.to_a.map { |v| [v.sku, v.total_quantity_sold] }
variants.to_a.map { |v| [v.descriptive_name, v.total_quantity_sold] }
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 180],
[product2.master.sku, 20]
[variant1.descriptive_name, 180],
[product2.master.descriptive_name, 20]
]
end
end
Expand All @@ -59,9 +59,9 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 180],
[product1.master.sku, 30],
[product2.master.sku, 20]
[variant1.descriptive_name, 180],
[product1.master.descriptive_name, 30],
[product2.master.descriptive_name, 20]
]
end
end
Expand All @@ -78,8 +78,8 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 180],
[product2.master.sku, 20]
[variant1.descriptive_name, 180],
[product2.master.descriptive_name, 20]
]
end
end
Expand All @@ -97,7 +97,7 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 180]
[variant1.descriptive_name, 180]
]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 2],
[product2.master.sku, 1]
[variant1.descriptive_name, 2],
[product2.master.descriptive_name, 1]
]
end
end
Expand All @@ -59,9 +59,9 @@
array = subject.call

expect(array).to eq [
[product1.master.sku, 3],
[variant1.sku, 2],
[product2.master.sku, 1]
[product1.master.descriptive_name, 3],
[variant1.descriptive_name, 2],
[product2.master.descriptive_name, 1]
]
end
end
Expand All @@ -78,8 +78,8 @@
array = subject.call

expect(array).to eq [
[variant1.sku, 2],
[product2.master.sku, 1]
[variant1.descriptive_name, 2],
[product2.master.descriptive_name, 1]
]
end
end
Expand All @@ -97,7 +97,7 @@
array = subject.call

expect(array).to eq [
[product1.master.sku, 3]
[product1.master.descriptive_name, 3]
]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
end

it 'return JSON data for charts' do
expect(json_response['labels']).to eq [variant1.sku, product1.master.sku, product2.master.sku]
expect(json_response['labels']).to eq [
variant1.descriptive_name,
product1.master.descriptive_name,
product2.master.descriptive_name
]
expect(json_response['data'].map(&:to_f)).to eq [180, 30, 20]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
end

it 'return JSON data for charts' do
expect(json_response['labels']).to eq [product1.master.sku, variant1.sku, product2.master.sku]
expect(json_response['labels']).to eq [
product1.master.descriptive_name,
variant1.descriptive_name,
product2.master.descriptive_name
]
expect(json_response['data']).to eq [3, 2, 1]
end
end
Expand Down