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

Remove hard dependency between order of results and observations #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/reports/spree/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_results

query = query.order(active_record_sort) if sortable_attribute.present?
query_sql = query.to_sql
r = ActiveRecord::Base.connection.exec_query(query_sql)
ActiveRecord::Base.connection.exec_query(query_sql)
end

def set_sortable_attributes(options, default_sortable_attribute)
Expand Down
6 changes: 3 additions & 3 deletions app/reports/spree/report/date_slicer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.slice_into(start_date, end_date, time_scale, klass)
def self.slice_hours_into(start_date, end_date, klass)
current_date = start_date
slices = []
while current_date < end_date
while current_date <= end_date
slices << (0..23).collect do |hour|
obj = klass.new
obj.date = current_date
Expand All @@ -30,7 +30,7 @@ def self.slice_hours_into(start_date, end_date, klass)
def self.slice_days_into(start_date, end_date, klass)
current_date = start_date
slices = []
while current_date < end_date
while current_date <= end_date
obj = klass.new
obj.date = current_date
slices << obj
Expand All @@ -42,7 +42,7 @@ def self.slice_days_into(start_date, end_date, klass)
def self.slice_months_into(start_date, end_date, klass)
current_date = start_date
slices = []
while current_date < end_date
while current_date <= end_date
obj = klass.new
obj.date = current_date
slices << obj
Expand Down
16 changes: 2 additions & 14 deletions app/reports/spree/report/timed_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,9 @@ def build_empty_observations
end

def populate_observations
observation_iter = @observations.each
current_observation = @observations.present? ? observation_iter.next : nil
@results.each do |result|
if current_observation.present?
begin
until current_observation.describes? result, time_scale
current_observation = observation_iter.next
end

current_observation.populate(result)
current_observation = observation_iter.next
rescue StopIteration
break
end
end
matching_observation = @observations.find { |observation| observation.describes? result, time_scale }
matching_observation.populate result
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/reports/spree/shipping_cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Observation < Spree::Report::TimedObservation
observation_fields [:name, :shipping_charge, :revenue, :shipping_cost_percentage]

def describes?(result, time_scale)
(name = result['name']) && super
(name == result['name']) && super
end

def shipping_cost_percentage
Expand All @@ -50,7 +50,7 @@ def report_query
'shipping_charge',
'shipping_method_id',
'name'
)
).order('shipping_method_id', *time_scale_columns)
end

private def order_with_shipments
Expand Down