Class: CustomerRequest

Inherits:
Request show all
Defined in:
app/models/customer_request.rb

Overview

A class for requests that have some business meaning outside of Sequencescape

Constant Summary

Constants included from Metadata

Metadata::SECTION_FIELDS

Constants included from Request::Statemachine

Request::Statemachine::ACTIVE, Request::Statemachine::COMPLETED_STATE, Request::Statemachine::INACTIVE, Request::Statemachine::OPENED_STATE, Request::Statemachine::SORT_ORDER

Instance Method Summary collapse

Methods inherited from Request

accessioning_required?, #add_comment, #aliquot_attributes, #associated_studies, #billing_product_identifier, #cancelable?, #copy, #current_request_event, delegate_validator, #event_with_key_value, #eventful_studies, for_study, #format_qc_information, #get_value, #has_passed, #lab_events_for_batch, #manifest_processed!, #next_request_type_id, #next_requests, #next_requests_via_asset, #next_requests_via_submission, number_expected_for_submission_id_and_request_type_id, #previous_failed_requests?, #priority, #product_line, #project=, #project_id=, #ready?, #request_type_updatable?, #return_pending_to_inbox!, #run_events, #source_labware, #study=, #study_id=, #submitted_at, #target_purpose, #target_tube, #update_pool_information, #update_priority, #value_for

Methods included from Metadata

#has_metadata, required_tags

Methods included from EventfulRecord

#has_many_events, #has_many_lab_events, #has_one_event_with_family

Methods included from Request::Statistics

#asset_statistics, #progress_statistics, #sample_statistics_new

Methods included from Request::CustomerResponsibility

included

Methods included from Batch::RequestBehaviour

#create_batch_request!, included, #recycle_from_batch!, #return_for_inbox!, #with_batch_id

Methods included from Request::Statemachine

#cancellable?, #change_decision!, #closed?, #failed_downstream!, #failed_upstream!, #finished?, included, #on_blocked, #on_cancelled, #on_failed, #on_hold, #on_passed, #on_started, #open?, #terminated?, #transfer_aliquots, #transition_to

Methods included from StandardNamedScopes

included

Methods included from Commentable

#after_comment_addition

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods included from Api::RequestIO::Extensions

included, #json_root

Methods included from Aliquot::DeprecatedBehaviours::Request

#sample_name, #tag, #tag_number

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Instance Method Details

#biffable?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'app/models/customer_request.rb', line 78

def biffable?
  billing_product.present?
end

#can_be_billed?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/models/customer_request.rb', line 74

def can_be_billed?
  passed? && biffable? && billing_items.empty?
end

#create_billing_eventsObject


69
70
71
72
# File 'app/models/customer_request.rb', line 69

def create_billing_events
  factory = Billing::Factory.build(self)
  factory.create! if factory.valid?
end

#customer_accepts_responsibility!Object


18
19
20
# File 'app/models/customer_request.rb', line 18

def customer_accepts_responsibility!
  .update!(customer_accepts_responsibility: true)
end

#generate_create_request_eventRequestEvent

Generate a request event indicating the request has been created

Returns:


27
28
29
30
31
32
33
# File 'app/models/customer_request.rb', line 27

def generate_create_request_event
  request_events.create!(
    event_name: 'created',
    to_state: state,
    current_from: DateTime.current
  )
end

#generate_destroy_request_eventRequestEvent

Generate a request event indicating the request has been destroyed

Returns:


57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/customer_request.rb', line 57

def generate_destroy_request_event
  time = DateTime.current
  current_request_event&.expire!(time)
  request_events.create!(
    event_name: 'destroyed',
    from_state: state,
    to_state: state,
    current_from: time,
    current_to: time
  )
end

#generate_request_eventRequestEvent

Generate a request event for the state transition and expires existing events for existing events.

Returns:


41
42
43
44
45
46
47
48
49
50
# File 'app/models/customer_request.rb', line 41

def generate_request_event
  time = DateTime.current
  current_request_event&.expire!(time)
  request_events.create!(
    event_name: 'state_changed',
    from_state: state_before_last_save,
    to_state: state,
    current_from: time
  )
end

#update_responsibilities!Object


12
13
14
15
16
# File 'app/models/customer_request.rb', line 12

def update_responsibilities!
  return if qc_metrics.stock_metric.empty?

  customer_accepts_responsibility! if qc_metrics.stock_metric.all?(&:poor_quality_proceed)
end