Class: InterventionInput

Inherits:
InterventionProductParameter show all
Defined in:
app/models/intervention_input.rb

Overview

An intervention input represents a product which is used and “consumed” by the intervention. The input is divided from a source product. Its tracking number follows the new product.

Instance Method Summary collapse

Methods inherited from InterventionProductParameter

#default_name, #human_quantity, #measurable?, #name, #quantity_handler_reference, role, #role, #runnable?, #set_default_name!, #working_zone_svg

Methods inherited from InterventionParameter

#cost, #earn, #earn_amount_computation, #reference, #runnable?

Methods inherited from Ekylibre::Record::Base

#already_updated?, attr_readonly_with_conditions, #check_if_destroyable?, #check_if_updateable?, columns_definition, complex_scopes, customizable?, #customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, human_attribute_name_with_id, nomenclature_reflections, #old_record, #others, refers_to, scope_with_registration, simple_scopes, #updateable?

Instance Method Details

#cost_amount_computationObject


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/intervention_input.rb', line 76

def cost_amount_computation
  return InterventionParameter::AmountComputation.failed unless product
  incoming_parcel = product.incoming_parcel_item
  options = { quantity: quantity_population, unit_name: product.unit_name }
  if incoming_parcel && incoming_parcel.purchase_item
    options[:purchase_item] = incoming_parcel.purchase_item
    return InterventionParameter::AmountComputation.quantity(:purchase, options)
  else
    options[:catalog_usage] = :purchase
    options[:catalog_item] = product.default_catalog_item(options[:catalog_usage])
    return InterventionParameter::AmountComputation.quantity(:catalog, options)
  end
end