Class: InterventionOutput

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

Overview

An intervention output represents a product which is produced by the intervention. The output generate a product with the given quantity.

Instance Method Summary collapse

Methods inherited from InterventionProductParameter

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

Methods inherited from InterventionParameter

calculate_cost_amount_computation, compare_with_planned, #cost, #cost_amount_computation, #earn, order_by_product_name, #reference, #role, role, #runnable?

Methods inherited from Ekylibre::Record::Base

#already_updated?, #check_if_destroyable?, #check_if_updateable?, columns_definition, #customizable?, customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, nomenclature_reflections, #old_record, #others, refers_to, #unsuppress, #updateable?

Methods included from Userstamp::Stampable

included

Methods included from Userstamp::Stamper

included

Instance Method Details

#compute_output_planting_nameObject


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/models/intervention_output.rb', line 126

def compute_output_planting_name
  compute_name = []
  if group && group.targets.any?
    land_parcel = group.targets.detect { |target| target.product.is_a?(LandParcel) }
    compute_name << land_parcel.product.name if land_parcel
  end

  return output_name_without_params(compute_name) if variety.blank? && batch_number.blank?

  compute_name << variety if variety.present?
  compute_name << batch_number if batch_number.present?

  output_duplicate_count = output_name_count(compute_name.join(' '))

  compute_name << "(#{output_duplicate_count})" unless output_duplicate_count.zero?
  compute_name.join(' ')
end

#earn_amount_computationObject


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/intervention_output.rb', line 105

def earn_amount_computation
  options = { quantity: quantity_population, unit_name: product.unit_name }
  if product
    outgoing_parcel = product.outgoing_parcel_item
    if outgoing_parcel && outgoing_parcel.sale_item
      options[:sale_item] = outgoing_parcel.sale_item
      return InterventionParameter::AmountComputation.quantity(:sale, options)
    else
      options[:catalog_usage] = :sale
      options[:catalog_item] = product.default_catalog_item(options[:catalog_usage])
      return InterventionParameter::AmountComputation.quantity(:catalog, options)
    end
  elsif variant
    options[:catalog_usage] = :sale
    options[:catalog_item] = variant.default_catalog_item(options[:catalog_usage])
    return InterventionParameter::AmountComputation.quantity(:catalog, options)
  else
    return InterventionParameter::AmountComputation.failed
  end
end

#stock_amountObject


101
102
103
# File 'app/models/intervention_output.rb', line 101

def stock_amount
  product_movement ? product_movement.population * unit_pretax_stock_amount : 0
end