Skip to content

Commit

Permalink
Brought up to date with master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aquaj committed Jun 28, 2017
2 parents 1060ff1 + 42fa1ba commit d8c3e5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/helpers/backend/products_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module ProductsHelper
# Show a chart with working time spent between different activities
# It can accept :cobbler option to specify inclusion.
def time_spent_by_activity(resource, options = {})
working_periods = InterventionWorkingPeriod.with_intervention_parameter(options[:as] || :tool, resource)
working_periods = InterventionWorkingPeriod.precise_working_periods(options[:as] || :tool, resource)

working_periods = working_periods.of_campaign(current_campaign) if options[:current_campaign]
return nil unless current_campaign && working_periods.any?
stopped_at = working_periods.reorder(stopped_at: :desc).first.stopped_at.to_date
Expand Down
2 changes: 2 additions & 0 deletions app/models/intervention_participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class InterventionParticipation < Ekylibre::Record::Base
where(intervention_id: intervention)
}

scope :of_actor, ->(actor) { where(product_id: actor.id) }

before_save do
if intervention.present?
intervention.update_state(id => state)
Expand Down
8 changes: 8 additions & 0 deletions app/models/intervention_working_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class InterventionWorkingPeriod < Ekylibre::Record::Base
where(intervention_participation: intervention_participations)
}

scope :without_participants_intervention, lambda { |role, object|
where.not(intervention_id: InterventionParticipation.of_actor(object).pluck(:intervention_id).compact)
}

scope :precise_working_periods, lambda{|role, object|
where(id: (InterventionWorkingPeriod.with_intervention_parameter(role,object).without_participants_intervention(role,object).pluck(:id) + InterventionWorkingPeriod.of_intervention_participations(object.intervention_participations).pluck(:id)))
}

scope :of_nature, lambda { |nature|
where(nature: nature)
}
Expand Down

0 comments on commit d8c3e5c

Please sign in to comment.